带有省略号和nowrap白色空格的textwrap

时间:2013-08-29 00:36:10

标签: html css

我想使用ellipsis切断一些长文本。

但是,对于我当前的实现,它不包含会导致它超出div的额外单词,并且不会显示ellipsis以指示文本被截断。

我做错了什么?

http://jsfiddle.net/sw6Sp/6/

<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;
}

2 个答案:

答案 0 :(得分:8)

只需使用text-overflow: ellipsiswhite-space: nowrap

Updated Example

.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>
相关问题