4

I am trying to implement Ellipsis after few lines. I have implemented this

https://jsfiddle.net/eqo74h3p/1/

It is working in Chrome but not in Firefox, IE.

css

 line-height: 1.7; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; 
3
  • 1
    -webkit- only works in WebKit browsers like Chrome & Safari. Commented Nov 17, 2016 at 13:09
  • Yeah, but what about firefox,IE. Any alternative? Commented Nov 17, 2016 at 13:10
  • 1
    Not that I know of. Also note that display: -webkit-box is old and you should use display: flex;. Commented Nov 17, 2016 at 13:14

3 Answers 3

2

Because Firefox doesn’t support webkit-line-clamp (then doesn't show ellipsis), we can do some tricks with ::after selector (without text-overflow: ellipsis; and -webkit-line-clamp: 4;), something like this:

For Firefox (also for IE or other browser):

p { border: 1px solid black; padding: 15px; width: 400px; height: 85px; max-height:72px; line-height: 21px; margin: 0 0 15px 0; font-size: 14px; position:relative; overflow: hidden; display: -webkit-box; word-break: break-all; } p::after { letter-spacing: .10em; content:"..."; position:absolute; bottom:0; right:-10px; padding:0 11px 4px 45px; }
<p> Lorem ipsum dolor sit amet, consectetur adipiscing 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. </p>

It is showing dots even if it is a single line

We can do some Jquery tricks to add ellipsis only if needed. (Just an Idea)

See this simple DEMO to explain my idea, I hope it helps.

var el = $('.P_One'); var bo = $('.One'); var el2 = $('.P_Two'); var bo2 = $('.Two'); if (el.get(0).scrollHeight > bo.height()) { document.styleSheets[0].addRule('.P_One::after','content:"..."; letter-spacing: .10em; position:absolute; bottom:0; right:-10px; padding:0 11px 4px 45px;'); } if (el2.get(0).scrollHeight > bo2.height()) { document.styleSheets[0].addRule('.P_Two::after','content:"..."; letter-spacing: .10em; position:absolute; bottom:0; right:-10px; padding:0 11px 4px 45px;'); }
.One{ width: 400px; height: 85px; max-height:72px; margin-bottom:40px; } .P_One, .P_Two { border: 1px solid black; padding: 15px; width: 400px; height: 85px; max-height:72px; line-height: 21px; margin: 0 0 15px 0; font-size: 14px; position:relative; overflow: hidden; display: -webkit-box; word-break: break-all; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="One">	<p class="P_One">	Lorem ipsum dolor sit amet, consectetur adipiscing 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.	</p> </div> <div class="Two">	<p class="P_Two">	Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.	</p> </div>

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding white-space: nowrap;

https://jsfiddle.net/eqo74h3p/2/

Comments

0

Well there are some few reasons for why your CSS is not working, use my css setting below for the right way:

p { border: 1px solid black; padding: 10px; display: -webkit-box; // use this not the block height: 85px; // change this lower then the lines you have margin: 0 0 15px 0; font-size: 14px; line-height: 17px; // use pixels nog 1.7 -webkit-line-clamp: 4; // use this and put in more lines then 4. -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; word-break: break-all; } 

Hopefully this will work for you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.