Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS word-break combined with text-overflow

Tags:

css

So I am trying to combine word-break with text-overflow which does work at some point but not how it should be.

For example, I have set up this Fiddle

CSS:

width: 200px;
padding: 8px;
border:1px solid blue;
word-break: break-word;
height: 100px;
overflow: hidden;
text-overflow:ellipsis;
white-space:nowrap;

For clarification, once text is broken in to parts it should fill box and at the end of the text there should be 3 dots. Currently there is just a single line where it works.

like image 820
Linas Avatar asked Dec 15 '12 18:12

Linas


People also ask

How do you break overflow words in CSS?

The overflow-wrap CSS property applies to inline elements, setting whether the browser should insert line breaks within an otherwise unbreakable string to prevent text from overflowing its line box.

How do you automatically break text in CSS?

The overflow-wrap property in CSS allows you to specify that the browser can break a line of text inside the targeted element onto multiple lines in an otherwise unbreakable place. This helps to avoid an unusually long string of text causing layout problems due to overflow.

How do I force a break in CSS word?

The word-break property in CSS is used to specify how a word should be broken or split when reaching the end of a line. The word-wrap property is used to split/break long words and wrap them into the next line. word-break: break-all; It is used to break the words at any character to prevent overflow.

Is word-break deprecated?

Note: While word-break: break-word is deprecated, it has the same effect, when specified, as word-break: normal and overflow-wrap: anywhere — regardless of the actual value of the overflow-wrap property.


1 Answers

As far as I know, this is not possible using CSS.

The only thing you could do is specify the height, and overflow:hidden. (No ellipsis in the end.)

This is stated in the W3 spec for text-overflow.

ellipsis
an ellipsis string is inserted at each box boundaries where a text overflow occurs. The values of these ellipsis strings is determined by the 'text-overflow-ellipsis' property. The insertions take place at the boundary of the last full glyph representation of a line of text
...
In other words, the text-overflow-mode only affects the textual content of a block element which participate in its own inline flow.

You will need to use JavaScript for achieving this.

Here is an example of a jQuery plugin : http://pvdspek.github.com/jquery.autoellipsis/

like image 146
Pranav 웃 Avatar answered Sep 28 '22 09:09

Pranav 웃