如何限制文本宽度 [英] How to limit text width

查看:100
本文介绍了如何限制文本宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想限制一段文本的宽度,以便它看起来像在每行的内容中都有br。



类似这样:

  Texttttttttttttttttttt 
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆