我有一个情况,可能出现像“hellowordsometext”这样没有任何空格的长单词或整数, 请检查这个js代码。 http://jsfiddle.net/rzq5e/6/
如何在超过div宽度后将其换行。目前的情况是,它会和div一起延伸出去。
<div>Solutionforentprise</div>
我有一个情况,可能出现像“hellowordsometext”这样没有任何空格的长单词或整数, 请检查这个js代码。 http://jsfiddle.net/rzq5e/6/
如何在超过div宽度后将其换行。目前的情况是,它会和div一起延伸出去。
<div>Solutionforentprise</div>
你需要的是 word-wrap: break-word;
,这个属性将强制非空格字符串在
div {
width: 20px;
word-wrap: break-word;
}
我自己找到了这个解决方案。
word-break: break-all;
但是对于 Opera 浏览器无效。
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-break其他答案在旧浏览器(如Chrome 32之前的版本)存在一些问题。
最好使用以下代码:
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
.c1 {
width: 200px;
border: 1px solid;
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
<div class="c1">
For more information, please visit: http://csstricks.com/thisisanonexistentandreallylongurltoaddtoanytextinfactwhyareyoustillreadingit.
</div>
#divid
{
width: 30px;
word-wrap: break-word;
}
自动换行功能在IE 5.5+、Firefox 3.5+以及Chrome和Safari等WebKit浏览器,Opera 10.5+中得到支持。
修复 DIV 的尺寸并应用 'overflow: hidden',这样它就不会影响到网格的大小。
div{width: 40px;
overflow: hidden;}
你需要查看完整的文本吗?