Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have text-overflow: ellipsis without white-space: nowrap?

Tags:

css

typography

It seems that text-overflow: ellipsis is dependent on white-space: nowrap. The problem with this is that it limits the text to one line. However, what if I need to have 4 lines, and the ellipsis on the last line in the case of overflow?

What it's currently doing...

Lorem ipsum dolor sit amet ...

What I want...

Lorem ipsum dolor sit amet, 
consectetur adipisicing el-
it, sed do eiusmod tempor  
incididunt ut labore et ...
like image 381
T. Stone Avatar asked Nov 09 '11 16:11

T. Stone


People also ask

How do I force text overflow ellipsis?

To force overflow to occur and ellipses to be applied, the author must apply the nowrap value to the white-space property on the element, or wrap the content in a <NOBR> tag.

Why text overflow ellipsis is not working?

text-overflow: ellipsis only works when the following is true: The element's width must be constrained in px (pixels) – it doesn't work with values specified using % (percent.) The element must have following properties set: overflow: hidden and white-space: nowrap.

What is whitespace 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 I make my text overflow hidden?

A text-overflow property in CSS is used to specify that some text has overflown and hidden from view. The white-space property must be set to nowrap and the overflow property must be set to hidden. The overflowing content can be clipped, display an ellipsis ('…'), or display a custom string.


1 Answers

Unfortunately the behavior you are seeing is correct for text-overflow: ellipsis.

Cross-browser support for hyphenated text is not a reality yet with CSS only, but you can see a good roundup of what's possible here: http://code.google.com/p/hyphenator/wiki/en_CSS3Hyphenation

Some browser-specific CSS is available for firefox and webkit browsers:

-webkit-hyphens: auto;
-webkit-hyphenate-character: '~';
-moz-hyphens: auto;

The big issue with hyphenation is that it needs to be language aware to work properly, which is tricky.

Maybe a JS solution like this will help you? http://code.google.com/p/hyphenator/

like image 85
squarecandy Avatar answered Nov 12 '22 14:11

squarecandy