如果文本长度增加jquery,则隐藏溢出

时间:2014-05-22 08:01:11

标签: javascript jquery css css3

第一手见fiddle

我所拥有的是一个带字符串的div。现在每当hover .dots bolderlength内的文字会增加其sizeoverflow:hidden。我希望类似于文字大小增加然后它不应该像3 dots那样消失,但显示后面跟dots。例如,看看这个图像........

1

由于名称太长,因此显示{{1}}。我怎么可能这样做?

3 个答案:

答案 0 :(得分:3)

尝试text-overflow:ellipsis;white-space:nowrap

.dots {
 height:20px;
 width:150px;
 background:#fff;
 border:1px solid #DDD;
 color:#333;
 text-overflow:ellipsis;
 overflow:hidden;
 padding:2px;
 white-space: nowrap;
}

演示:http://jsfiddle.net/lotusgodkk/K655K/1/

答案 1 :(得分:2)

将此添加到您的css类:

    .dots {
          .....
        overflow:hidden;
        padding:2px;
        text-overflow: ellipsis; // required
        white-space: nowrap; // required
    }

答案 2 :(得分:2)

这是一个非常简单的解决方案。 只需将其添加到您的.dots css:

white-space: nowrap;
text-overflow: ellipsis;

所以你的css看起来像这样:

.dots {
    height:20px;
    width:150px;
    background:#fff;
    border:1px solid #DDD;
    color:#333;
    overflow:hidden;
    padding:2px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

请参阅我制作的fiddle