我想使用ellipsis
切断一些长文本。
但是,对于我当前的实现,它不包含会导致它超出div
的额外单词,并且不会显示ellipsis
以指示文本被截断。
我做错了什么?
<div class="testWrap">This is some very long text that I want to cut off </div>
.testWrap{
max-width: 125px;
height:15px;
overflow: hidden;
text-overflow:ellipsis;
border: 1px solid black;
}
答案 0 :(得分:8)
只需使用text-overflow: ellipsis
和white-space: nowrap
。
.testWrap {
width: 125px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
答案 1 :(得分:4)
添加css-rule white-space: nowrap;
可以解决您的问题。
<div class="testWrap" style="
max-width: 125px;
height:15px;
overflow: hidden;
text-overflow:ellipsis;
border: 1px solid black;
white-space: nowrap;
">This is some very long text that I want to cut off </div>