-1

I have problem with adding 3 dots on the end of div. I my text is too long and don;'t have enough space to display, on the of div I want to display 3 dots.

I know for text-overflow ellipsis but now workig correct on IE and Firefox.

Is it possible to do on another way.

https://jsfiddle.net/kq1Lp6og/

I want to create ease in CSS, but don't know how without ellipsis.

HTML

<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

CSS

 div{
  height:38px !important;
  overflow: hidden;
 }
ml92
  • 441
  • 3
  • 7
  • 19
  • 1
    you shouldn't use !important. If you use that, it means that you're not using classes correctly. !important will have higher rule weight than everything, and if your html is very big, you can have problems. – xale94 Nov 07 '16 at 13:16

2 Answers2

2

div {
  max-width:100%;
  height:38px;
  overflow: hidden;
  position: relative;
  line-height: 1em;
  max-height: 3em;
  text-align: justify;
  padding-right: 1em;
  font-size: 20px;
}
div:before {
  content: '...';
  position: absolute;
  right: 2px;
  bottom: 0px;
}
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
0

I know you asked for CSS, but you may (or future readers may) not want CSS: it doesn't update when window size changes and it's not a very good nor flexible nor easy method to have "...", I had the same problem that I tried to fix with CSS and I finally use a JS library called dotdotdot.

PS : please do not dislike because it doesn't match all the criteria, I had exactly the same problem and I understood that CSS isn't necessarily the best option (for user experience and developer) so it's important that you know all the option you have.

Ilan Schemoul
  • 1,461
  • 12
  • 17