如果超过设置宽度,则在div中截断文本? [英] Cut off text in a div if it exceeds set width?
问题描述
在一个网站上,我正在为用户添加一个标题。 M11-001 - 从曼彻斯特的集装箱和货物损失
有些标题,深度。在现实中,至少对于标题,这个内容并不总是需要的。前几句话足以区分记录。
我可以设置overflow:hidden到div,并且无缝切割设置宽度以外的任何东西。
我想要添加...到最后。像这样:
M11-001 - 容器丢失...
pre>
因此,在X宽度或X字符后添加三个完整停止。
使用CSS,或者可能是JavaScript吗?
解决方案这样的东西? http://www.quirksmode.org/css/textoverflow.html
文本溢出
文本溢出声明允许
处理剪辑文本:
是,不适合它的
框中的文本。省略号值导致三个
期间附加到文本。
On a website I am working on users can add a heading to a section of a page.A simple example:
M11-001 - loss of container and goods from Manchester
With some headings the content can be quite in-depth. In reality, for the heading at least, this content isn't always needed. The first few words would suffice to differentiate between records.
I could just set overflow:hidden to the div and ruthlessly cut of anything outside of the set width.
I would prefer to add ... To the end. Like so:
M11-001 - loss of container...
So three full-stops would be added after either X width or X characters.
Is this possible with CSS, or maybe JavaScript?
解决方案Something like this? http://www.quirksmode.org/css/textoverflow.html
Text-Overflow
The text-overflow declaration allows you to deal with clipped text: that is, text that does not fit into its box. The ellipsis value causes three periods to be appended to the text.
这篇关于如果超过设置宽度,则在div中截断文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!