如果太大,请在HTML文本中添加省略号 [英] Add an ellipsis to HTML text if it is too large
本文介绍了如果太大,请在HTML文本中添加省略号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果字符串太大,是否可以在字符串中添加省略号(三个点)?
Is there a way to add an ellipsis (three dots) to a string if it is too large?
例如.
发件人:
This is a very large sentence.
收件人:
This is a ve...
这可能是在服务器端使用PHP的 wordwrap
完成的,但当时很难获得渲染的大小,因此有一种更好的,标准的方法可以在JavaScript端使用JavaScript来实现,HTML还是CSS?
It may be done using PHP's wordwrap
on server side but at that time it is difficult to get the rendered size, so is there a better, standard way to do it on client side using JavaScript, HTML or CSS ?
在这里,我附有一张图片,以防万一您听不懂我在说什么.
Here I have included a picture just in case you do not really get what I am saying.
推荐答案
理想的方法是使用 css文本溢出属性:
Ideal way would be to use css text-overflow property:
p {
white-space: nowrap;
width: 100%;
overflow: hidden; /* "overflow" value must be different from "visible" */
text-overflow: ellipsis;
}
这篇关于如果太大,请在HTML文本中添加省略号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文