码迷,mamicode.com
首页 > 其他好文 > 详细

文字超出省略号显示

时间:2017-01-20 18:03:11      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:csdn   idt   line   mil   http   while   lin   pac   lamp   

一行

div{

    width:100px;/*一定要写*/

    white-space:nowrap;

    overflow:hidden;

    text-overflow:ellipsis;

}

来源于 http://blog.csdn.net/u011546766/article/details/34446737

 

 

多行

google浏览器

div{

    overflow:hidden;

    text-overflow:ellipsis; 

    display:-webkit-bos;

    -webkit-line-clamp:2;/*2行溢出隐藏*/

    -webkit-box-orient:vertical;

}

 

opera浏览器

div{

    overflow:hidden;

    white-space:normal;

    height:2rem;/*2行溢出隐藏*/

    text-overflow:-o-ellipsis-lastline;

}

 

全部兼容用js实现

$("div").each(function(i){
    var divH = $(this).height();
    var $p = $("p", $(this)).eq(0);
    while ($p.outerHeight() > divH) {
    $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
    };
});

 

来源于http://c7sky.com/text-overflow-ellipsis-on-multiline-text.html

 

文字超出省略号显示

标签:csdn   idt   line   mil   http   while   lin   pac   lamp   

原文地址:http://www.cnblogs.com/kcat/p/6323144.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!