Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

文本,可以根据字数的长度,控制...显示吗

image.png
像这样,在第二行显示...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

多行显示“...”,一般可以通过css方法实现,也可以通过js方法实现
像截图中的效果,肯定是通过js方法实现的。当超过一定字数后,截取文本,加上“...”就行

额外介绍css方法实现,
单行:

white-space: nowrap;
overflow:hidden;
text-overflow:ellipsis;

多行(部分浏览器有兼容性问题):

display:-webkit-box;
overflow:hidden;
text-overflow:ellipsis;
-webkit-line-clamp:2; // 控制显示行数
-webkit-box-orient:vertical;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...