css 截取文字

工作中遇到新闻列表 需要限制下字符的长度。

后端的同事估计嫌麻烦,交给前段做了。

li{

200px;

height:14px;

overflow:hidden;

white-space:nowrap;

text-overflow:ellipsis;

text-overflow: ellipsis;/* IE/Safari */

-ms-text-overflow: ellipsis;

-o-text-overflow: ellipsis;/* Opera */

-moz-binding: url("ellipsis.xml#ellipsis");/*FireFox*/

}

如果只有overflow:hidden 。那么生生切断,如果不精确,还漏半个字。

所以要加上

white-space:nowrap; //文字不换行

text-overflow:ellipsis; //省略后用...代替。

原文地址:https://www.cnblogs.com/smjia/p/3685265.html