天天看点

前端html多的字显示成省略号

之前处理这类问题,都是采用后端的方法。使用php的mb_substr($str,“utf-8”)方法,会产生问题。现在用样式来控制:

  1. 多行:
<style type="text/css">
.p1{
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
</style>
           
  1. 一行:

    超出一行用ellipsis显示

.product-buyer-name {
max-width: 110px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;  //文本不换行,这样超出一行的部分被截取,显示...
}
           

参考:https://blog.csdn.net/liwenfei123/article/details/69666880

继续阅读