首页 > 其他 > 详细

文字超出省略号显示

时间:2017-01-20 18:00:53      阅读:297      评论:0      收藏:0      [点我收藏+]

一行

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

 

文字超出省略号显示

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!