html - text-overflow: ellipsis not working

ID : 10012

viewed : 26

Tags : htmlcsshtml

Top 5 Answer for html - text-overflow: ellipsis not working

vote vote

98

You need to have CSS overflow, width (or max-width), display, and white-space.

http://jsfiddle.net/HerrSerker/kaJ3L/1/

span {     border: solid 2px blue;     white-space: nowrap;     text-overflow: ellipsis;     width: 100px;     display: block;     overflow: hidden } 

body {     overflow: hidden; }  span {     border: solid 2px blue;     white-space: nowrap;     text-overflow: ellipsis;     width: 100px;     display: block;     overflow: hidden }
<span>Test test test test test test</span>


Addendum If you want an overview of techniques to do line clamping (Multiline Overflow Ellipses), look at this CSS-Tricks page: https://css-tricks.com/line-clampin/

Addendum2 (May 2019)
As this link claims, Firefox 68 will support -webkit-line-clamp (!)

vote vote

89

Make sure you have a block element, a maximum size and set overflow to hidden. (Tested in IE9 and FF 7)

http://jsfiddle.net/uh9zD/

div {     border: solid 2px blue;     white-space: nowrap;     overflow: hidden;     text-overflow: ellipsis;     width: 50px; } 
vote vote

79

For multi-lines in Chrome use :

display: inline-block; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; // max nb lines to show -webkit-box-orient: vertical; 

Inspired from youtube ;-)

vote vote

66

For multiple lines

In chrome, you can apply this css if you need to apply ellipsis on multiple lines.

You can also add width in your css to specify element of certain width:

.multi-line-ellipsis {      overflow: hidden;      display: -webkit-box;      -webkit-line-clamp: 3;      -webkit-box-orient: vertical;  }
<p class="multi-line-ellipsis">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

vote vote

59

word-wrap: break-word; 

this and only this did the job for me for a

<pre> </pre>  

tag

everthing else failed to do the ellipsis....

Top 3 video Explaining html - text-overflow: ellipsis not working

Related QUESTION?