with
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
"..." will be shown in the end of the line if overflowed. However, this will be shown only in one line. But I would like it to be shown in multi-lines.
It may looks like:
+--------------------+
|abcde feg hij dkjd|
|dsji jdia js ajid s|
|jdis ajid dheu d ...|/*Here it's overflowed, so "..." is shown. */
+--------------------+
There are many answers here but I needed one that was:
The caveat is that it doesn't provide an ellipsis for the browsers that don't support the
-webkit-line-clamp
rule (currently IE, Edge, Firefox) but it does use a gradient to fade their text out.You can see it in action in this CodePen and you can also see a Javascript version here (no jQuery).
There are also several jquery plugins that deal with this issue, but many do not handle multiple lines of text. Following works:
There also some preformance tests.
Great question... I wish there was an answer, but this is the closest you can get with CSS these days. No ellipsis, but still pretty usable.
thanks @balpha and @Kevin, I combine two method together.
no js needed in this method.
you can use
background-image
and no gradient needed to hide dots.the
innerHTML
of.ellipsis-placeholder
is not necessary, I use.ellipsis-placeholder
to keep the same width and height with.ellipsis-more
. You could usedisplay: inline-block
instead.jsfiddler
a pure css method base on -webkit-line-clamp: