Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pure CSS multiline text with ellipsis
/* http://martinwolf.org/2013/01/29/pure-css-multiline-text-with-ellipsis/ */
$font-size: 26px;
$line-height: 1.4;
$lines-to-show: 3;
h2 {
display: block; /* Fallback for non-webkit */
display: -webkit-box;
max-width: 400px;
height: $font-size*$line-height*$lines-to-show; /* Fallback for non-webkit */
margin: 0 auto;
font-size: $font-size;
line-height: $line-height;
-webkit-line-clamp: $lines-to-show;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
@solankepl

This comment has been minimized.

Copy link

@solankepl solankepl commented Jun 24, 2016

we can't show ellipsis(...) in firefox and ie11.

@gNesh01

This comment has been minimized.

Copy link

@gNesh01 gNesh01 commented Sep 22, 2016

solankepl 👍

Cant make to work in FF and IE. Spend days figuring out that there is no css solution for this one..

@fuzzthink

This comment has been minimized.

Copy link

@fuzzthink fuzzthink commented Mar 7, 2017

@kogakure Seems like -webkit-box is a old 2009 version of flex. Replacing it with flex seems to break this implementation. The reason for trying to make it flex is not just due to keeping up with the spec, but I would like to have align-items: center; that works in flex but not -webkit-box. In summary, I need to set the div to a certain height and if the text is short, it is vertically centered; if it's long, it fills the space and ellipsis when text overflows.

@rares-preda

This comment has been minimized.

Copy link

@rares-preda rares-preda commented Feb 23, 2018

There are some solutions and most important one of them is written in pure-css and it is cross-browser.
http://hackingui.com/front-end/a-pure-css-solution-for-multiline-text-truncation/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment