[英]Word-wrap all text and fit div to size of a child?
I have the following html code: 我有以下html代码:
<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. 我需要div为
<label>
的宽度和要包装的文本。
Without the text, I can make .container inline-block so it fits to the label, but it will otherwise stretch with the text. 没有文本,我可以使.container内联块,使其适合标签,但否则会随着文本延伸。
Is this possible? 这可能吗?
The following example uses CSS to accomplish this: display: table-caption;
下面的示例使用CSS来完成此任务:
display: table-caption;
on the div
, and white-space: nowrap;
在
div
,以及white-space: nowrap;
on the label
. 在
label
。
Click the "Run code snippet" button below to see how it actually renders. 点击下面的“运行代码段”按钮,查看其实际呈现方式。 (It's just HTML with embedded CSS; no JavaScript.)
(这只是带有嵌入式CSS的HTML;没有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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.