如何限制文本宽度 [英] How to limit text width
问题描述
我想限制一段文本的宽度,以便它看起来像在每行的内容中都有br。
类似这样:
Texttttttttttttttttttt
$ p $
tttttttttttttttttttttttt
tttttttttttttttttttttttt
Texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
我试过指定div或p的宽度,但它不适用于我。任何建议?
解决方案您可以像这样应用css:
div {
word-wrap:break-word;
width:100px;
}
通常,浏览器不会打破单词,但
wrap:break-word;
会强制它打破单词。
演示: http://jsfiddle.net/Mp7tc/
有关详情单词包装
I would like to limit the width of a block of text so it will look like it has br at the ned of each line.
Something like this:
Texttttttttttttttttttttt tttttttttttttttttttttttt tttttttttttttttttttttttt
From this:
Texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
I have tried to specify the div's or p's width, but it didn't work for me. Any suggestions?
解决方案You can apply css like this:
div { word-wrap: break-word; width: 100px; }
Usually browser does not break words, but
word-wrap: break-word;
will force it to break words too.Demo: http://jsfiddle.net/Mp7tc/
More info about word-wrap
这篇关于如何限制文本宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!