Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webkit Line Clamp truncates link in the middle

Tags:

html

css

webkit

I have a link

<div class="module line-clamp">
   <a href='some url' target="_self">some really long text</a>
</div>

and this CSS

.module {
  width: 250px;
  overflow: hidden;
}
.line-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;  
}

I wanted to truncate this after 3 lines of text and put an ellipsis at the end like this

some
really
long ...

What actually happens is

some
really ...
text

If I change my html to be

<div class="module line-clamp">
   <p>some really long text</p>
</div>

then I do get

some
really
long ...

What am I missing?

Here's a JSFiddle.

like image 844
Sachin Kainth Avatar asked Aug 26 '14 09:08

Sachin Kainth


2 Answers

Hopefully, this helps someone in the future with a similar problem.

There was a simple solution to this simple problem. I put a p tag around the text of the anchor

<div class="module line-clamp">
   <a href='some url' target="_self"><p>some really long text</p></a>
</div>
like image 132
Sachin Kainth Avatar answered Oct 21 '22 10:10

Sachin Kainth


After reading Sachin's answer I tried adding an empty :after pseudo element and it also did the trick:

.line-clamp a:after { content: ""; }
like image 4
Fredrik Jungstedt Avatar answered Oct 21 '22 12:10

Fredrik Jungstedt