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.
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.
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.
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.
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.
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/
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