Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text wrap with fixed max-height

I need to have a box (div) with some text over multiple lines, and this box needs to have a fixed width and a fixed max height.

I'm using the overflow: hidden; Now my problem is that if the last line doesn't fit in the div max height it will get cut (cutting just half of the line for example). What I want to do in this case is not to show the last line, and display ellipsis in the last one

My problem is not inserting ellipsis in a single text line (using the white-space: nowrap property), the main problem is that the text gets cutted in the last line, ellipsis is not an issue because in last case I can use jQuery to insert it

like image 395
Zeux Avatar asked Oct 12 '12 14:10

Zeux


People also ask

What is the difference between word-wrap and word break?

The two properties ( word-break and word-wrap ) differ rules and overflow of words: as mentioned earlier, word-wrap is used to break words that overflow their container, while the word-break property breaks all words at the end of a line, even those that would normally wrap onto another line and wouldn't overflow their ...

How do you break a long text in CSS?

The <wbr> element If you know where you want a long string to break, then it is also possible to insert the HTML <wbr> element. This can be useful in cases such as displaying a long URL on a page.

Can I use overflow wrap anywhere?

The overflowing word that is otherwise unbreakable is broken into chunks of text using overflow-wrap: anywhere so that it fits in its container. It's important to note that anywhere is not yet supported by some browsers. The image below shows the browser support according to caniuse.com.

How do you text wrap in word?

Go to Picture Format or Shape Format and select Arrange > Wrap Text. If the window is wide enough, Word displays Wrap Text directly on the Picture Format tab. Choose the wrapping options that you want to apply. For example, In Line with Text, Top and Bottom, and Behind Text.


1 Answers

Add

text-overflow: ellipsis;

to the Div

EDIT: ok, not possible for now, not in a standardized way.

BUT, it's possible to achieve it with experimental webkit features (see this topic), or to do it with JS through the solution written by this guy, and hosted on github.

like image 94
Andrea Ligios Avatar answered Sep 21 '22 17:09

Andrea Ligios