How to add three dots in a multiline span
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.
So, my question was that I actually found the solution to this in another StackOverflow question, and that the solution is pretty simple. The link to the jsFiddle for the example is here, and also copied here for reference. HTML code:
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen look</span>
CSS code:
span{ display:inline-block; width:180px; white-space: nowrap; overflow:hidden !important; text-overflow: ellipsis; }
And it works like expected, it prints: Lorem Ipsum is simply du…
However, when I tried this in another example. JsFiddle is here. HTML code:
<div class="textContainer"> <img src="#" class="image" alt="the_image"> <span class="text">"The quick brown fox jumps over the lazy dog" is an english-language pangram, that is, a phrase that contains all of the letters of the English alphabet. It has been used to test typewriters and computer keyboards, and in other applications involving all of the letters in the English alphabet. Owing to its brevity and coherence, it has become widely known.</span> </div>
CSS code:
.textContainer{ width: 430px; float: left; margin-top: 10px; border: 1px solid black; } .text { font-size: 24px; line-height: 24px; font-weight: bold; color: #047F04; display: block; white-space: normal; overflow: hidden !important; text-overflow: ellipsis; height: 99px; } .image { float: right; position: absolute; top: 85px; right: 10px; width: 108px; height: 42px; }
So my question was how could I achieve to put … on the end of the string in my example?
The answer, by user devundef, was:
The specification for the
text-overflow
property says that this is not possible for multiline text:This property specifies rendering when inline content overflows its block container element (“the block”) in its inline progression direction that has ‘overflow’ other than ‘visible’. Text can overflow for example when it is prevented from wrapping (e.g. due to ‘white-space:nowrap’ or a single word is too long to fit).
In other words, only works on single line text blocks.
source: http://dev.w3.org/csswg/css3-ui/#text-overflow
EDIT This fiddle has a workaround using jquery: http://jsfiddle.net/k5VET/ (source: Cross browsers mult-lines text overflow with ellipsis appended within a width&height fixed div?)
Leave a Comment