如何防止div块中的文本在CSS中溢出?
HTML:
<div>This div contains a VeryLongWordWhichDoesNotFitToTheBorder.</div>
CSS:
div {
width: 150px;
/* what to put here? */
}
发布于 2010-09-25 05:16:14
如果希望div中的溢出文本自动换行,而不是隐藏或生成滚动条,请使用
word-wrap: break-word
属性。
发布于 2009-07-22 14:04:10
您可以尝试:
<div id="myDiv">
stuff
</div>
#myDiv {
overflow:hidden;
}
有关更多信息,请查看the docs for the overflow property。
发布于 2013-12-18 18:57:44
您可以使用CSS属性text-overflow截断长文本。
<div id="greetings">
Hello universe!
</div>
#greetings
{
width: 100px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis; // This is where the magic happens
}
参考:http://makandracards.com/makandra/5883-use-css-text-overflow-to-truncate-long-texts
https://stackoverflow.com/questions/1165497
复制相似问题