【发布时间】:2012-11-16 21:10:24
【问题描述】:
是否可以缩短容器(最好是 div),以便在不增加高度的情况下动态插入其中的文本成为“完美”矩形?
<div style="width:800px;">
<div>I'd like these words to look like below, but I'd like to "automatically" set it with a few lines of CSS rather than with jQuery or some other computationally intensive alternative.</div>
</div>
<br>
<div style="width:800px;">
<div style="width:530px;">I'd like these words to look like below, but I'd like to "automatically" set it with a few lines of CSS rather than with jQuery or some other computationally intensive alternative.</div>
</div>
如果可能的话,我想用一个 CSS 设置来做这件事,但我找不到。我还想避免 javascript 中的循环来执行此操作,因为我必须对很多 div 执行此操作,并且我不希望性能受到影响。
除非我用错了,否则空格似乎没有帮助。
提前非常感谢!
文本对齐:对齐;
本身没有帮助:http://jsfiddle.net/Q7gcb/4/
最大宽度 + 文本对齐:对齐;
【问题讨论】:
-
设置最大宽度,然后对齐文本?
-
我猜你的意思不是 text-align:justify?
-
不能手动设置。例如,在 IE9 或 Mac 上的 Chrome 中,
<div style="width:530px;">示例文本是三行长,而不是两行(由于不同的文本呈现方式)。我认为你需要 JavaScript。 -
感谢您的帮助和注意。已经尝试过javascript。它使我的页面断断续续。大量动态 div。
标签: css dynamic text width containers