Single line text
If it is just text-overflow:ellipsis, it has no effect, even if you add some width and height to it to limit the
code:
effect:
then you need to add:
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
code:
effect:
Multiline text
The code is as follows:
Note: The width and height need to be adjusted according to the actual
effect:
The CSS extension properties of WebKit are used above, and this method is suitable for WebKit browsers and mobile terminals;
Note:
-webkit-line-clamp用来限制在一个块元素显示的文本的行数。 为了实现该效果,它需要组合其他的WebKit属性。常见结合属性:
display: -webkit-box; 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。
-webkit-box-orient 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。
The compatibility of this method is not very good, it needs to be combined with js to optimize the use effect, such as:
set the height to an integer multiple of line-height to prevent the excess text from being exposed.
Adding a gradient background to p::after can prevent the text from being displayed in half.