css single line text beyond hiding and multiline text beyond hiding

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: Insert picture description here
effect: Insert picture description here
then you need to add:
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
code: Insert picture description here
effect:Insert picture description here

Multiline text

The code is as follows:
Note: The width and height need to be adjusted according to the actual
Insert picture description hereeffect:
Insert picture description here
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.

Guess you like

Origin blog.csdn.net/weixin_49549509/article/details/108304659