文本溢出、字符串过长截取多余文字并用省略号显示

1、字符串过长CSS截取多余文字并用省略号显示 

1 line-height: 30px;
2 text-align: center;
3 text-overflow:ellipsis;//让超出的内容用...实现
4 white-space:nowrap;//禁止换行
5 overflow:hidden;//超出的隐藏
6 display: block;
text-overflow:clip;//修剪文本。
text-overflow:ellipsis;//显示省略符号来代表被修剪的文本。

 

2、td内的文字超出显示省略号

        有时table需要固定高度和行数,在不确定数据长度的情况下,只能使td内的文字超出隐藏,以防止由于文字折行引起的结构错乱;
        注:必须放在父级table上添加table-layout:fixed;/* 固定表格布局 */
 

3、jQuery截取多余文字并用省略号显式

 

1 $(".contents").each(function() {
2     if ($(this).text().length > 50) {
3     var str = $(this).text($(this).text().trim().substring(0, 50));//截取50个字符
4         $(this).text($(this).text() + "…");
5     }
6 });

  

4、jQuery的文本溢出插件

 

posted @ 2015-09-01 11:23  staven  阅读(1116)  评论(0编辑  收藏  举报