溢出隐藏

css实现单行溢出隐藏

overflow: hidden;

text-overflow: ellipsis;

white-space: nowrap;

js实现多行溢出隐藏

 <dd class="user_star_dd"><p>你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好</p></dd>

 

overflow: hidden;

height: 30px;

 

$(".user_star_dd").each(function(i) {

  var divH = $(this).height();

  var $p = $("p", $(this));

  while ($p.outerHeight() > divH) {

    $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));

  };

})

posted @ 2018-09-19 10:28  趴着睡  阅读(174)  评论(0)    收藏  举报