I have the following html code:
<div class="container">
This is just some text. This is just some text. This is just some text.<br><br>
<label>Input: <input type="text"></label>
</div>
I need the div to be the width of the <label>
and the text to wrap.
Without the text, I can make .container inline-block so it fits to the label, but it will otherwise stretch with the text.
Is this possible?
The following example uses CSS to accomplish this: display: table-caption;
on the div
, and white-space: nowrap;
on the label
.
Click the "Run code snippet" button below to see how it actually renders. (It's just HTML with embedded CSS; no JavaScript.)
<div class="container" style="display: table-caption;"> This is just some text. This is just some text. This is just some text.<br><br> <label style="white-space: nowrap;">Input: <input type="text"></label> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.