HTML / CSS - 长字替换为

时间:2014-07-22 06:35:10

标签: javascript jquery html css

我真的不知道怎么称呼它所以我找不到好搜索。

我试图打破一个字,但我没有把字放在下一行,而是用...替换容器末端的字母。 更多类似于Facebook帖子上看到更多选项。

我该怎么做?

2 个答案:

答案 0 :(得分:3)

您可以使用css属性省略号,其中使用'...'来截断跟进的长度

.your_class {
    text-overflow: ellipsis;
}

可以从这个tutorial-ellipsis tricks

中学到更多东西

答案 1 :(得分:2)

您可以尝试以下代码:

Demo

<div id="div2">This is some long text that will not fit in the box</div>

#div2
 {
   white-space:nowrap; 
   width:12em; 
   overflow:hidden;
   text-overflow:ellipsis; 
   border:1px solid #000000;
 }