我需要在我的 DIV 元素中隐藏点 (...) 之后的额外文本
我正在使用
<div style="width:200px; height:2em; line-height:2em; overflow:hidden;" id="box">
this is text this is text this is text this is text
</div>
结果
它隐藏了溢出 DIV 的其余内容
但我希望如果它必须隐藏,那么三个点 ...
应该放在最后,否则不要
输出需求
这是文本 这是文本 这是 te...
最佳答案
这是一个使用 text-overflow:ellipsis
的可能解决方案:
.ellipsis {
width:200px;
height:2em;
line-height:2em;
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
}
关于javascript - 使用以下点隐藏 DIV 中的额外内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17733282/