Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textwrap with ellipsis and nowrap white-space

Tags:

html

css

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;
}
like image 239
scientiffic Avatar asked Aug 29 '13 00:08

scientiffic


People also ask

What is white-space Nowrap?

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.

How do you add an ellipsis in CSS?

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.

Can I use text-overflow ellipsis?

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.


2 Answers

Just use text-overflow: ellipsis along with white-space: nowrap.

Updated Example

.testWrap {
    width: 125px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
like image 183
Josh Crozier Avatar answered Sep 25 '22 12:09

Josh Crozier


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>
like image 21
Anthony Dekimpe Avatar answered Sep 25 '22 12:09

Anthony Dekimpe