CSS text wrapping and ellipsisPosted in 2011/04/22
Some of the relevant properties and W3Schools are referenced below:
The White-space property sets how to handle whitespace within an element.
Http://www.w3schools.com/css/pr_text_white-space.asp
White-space:normal | Nowarp | Pre | Pre-line | Pre-warp | Inherit
Word-warp property setting How to handle a word's wrapping
Http://www.w3schools.com/css3/css3_pr_word-wrap.asp
Word-wrap:normal | Break-word
Word-break property set How to handle word break, only IE is supported
Http://www.w3schools.com/css3/css3_pr_word-break.asp
Word-break:normal | Break-all | Hyphenate
Overflow property setting How to handle content outside of element borders
Http://www.w3schools.com/css/pr_pos_overflow.asp
overflow:visible | Hidden | Scroll | Auto | Inherit
Text-overflow is a relatively special property, for out-of-element border with the ellipsis display in general there is no perfect CSS solution, need help with JavaScript
Text-overflow:clip | ellipsis | Ellipsis-word
Clip: Do not display the ellipsis tag (...). ), but a simple cut
Ellipsis: Displays ellipsis (...) when text inside an object overflows. ), the position where the ellipsis is inserted is the last character.
Ellipsis-word: Displays ellipsis (...) when text inside an object overflows. ), the position of the ellipsis insertion is the last word (word).
Opera-o-text-overflow
Firefox3 not supported can solve this problem with-moz-bing (https://developer.mozilla.org/En/CSS/-moz-binding)
Help
01020304050607080910111213141516171819202122232425262728293031 |
<
title
>文字折行与省略号</
title
>
<
style type
=
"text/css"
>
p.nowarp {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;/*Not working in FF*/
}
p.warp {
overflow: hidden;
white-space: normal;
word-warp: break-word;
word-break: break-all;/*Only work in IE*/
text-overflow: ellipsis;/*Not working in FF*/
}
</
style
>
</
head
>
<
body
>
<
div style
=
"width: 300px; border: 1px solid red;"
>
<
p class
=
"nowarp"
>
禁止换行,且用省略号表示超出的部分,哈哈哈哈哈哈哈哈啊哈哈啊哈哈
</
p
>
</
div
>
<
div style
=
"width: 300px; border: 1px solid red;"
>
<
p class
=
"warp"
>
自动换行,veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylong
</
p
>
</
div
>
</
body
>
|
Display effects under IE and FF
CSS text wrapping and ellipsis