I would like to cut off some long text using an ellipsis
.
However, with my current implementation, it doesn't include extra words that would cause it to go beyond the div
and does not show ellipsis
to indicate that the text is cut off.
What am I doing wrong?
http://jsfiddle.net/sw6Sp/6/
<div class="testWrap">This is some very long text that I want to cut off </div>
.testWrap{
max-width: 125px;
height:15px;
overflow: hidden;
text-overflow:ellipsis;
border: 1px solid black;
}
nowrap. Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered.
To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: ''; . This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text.
Definition and Usage. The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.
Just use text-overflow: ellipsis
along with white-space: nowrap
.
Updated Example
.testWrap {
width: 125px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Adding the css-rule white-space: nowrap;
should solve your problem.
<div class="testWrap" style="
max-width: 125px;
height:15px;
overflow: hidden;
text-overflow:ellipsis;
border: 1px solid black;
white-space: nowrap;
">This is some very long text that I want to cut off </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With