user349072 user349072 - 2 months ago 4
CSS Question

CSS word ellipsis ('...') after one or two lines

I'm trying to create a word-wrap in JavaScript using CSS, and the condition is:

If DIV contains one very long word, such as "asdasfljashglajksgkjasghklajsghl", I want to display:


If DIV contains a long sentence, such as "if i had a dime for everytime i was told i can't", I want to display:

|if i had a dime for|
|everytime i was... |

I work with HTML, CSS, JavaScript. I can't use jQuery.

Please let me know if it's possible.


For this you can use text-overflow: ellipsis; property. Write like this

white-space: nowrap;
text-overflow: ellipsis;