Skip to content

Instantly share code, notes, and snippets.

@Camwyn
Created November 2, 2016 16:04
Show Gist options
  • Save Camwyn/6e659c60c5d3410c98edc792f12a01c2 to your computer and use it in GitHub Desktop.
Save Camwyn/6e659c60c5d3410c98edc792f12a01c2 to your computer and use it in GitHub Desktop.
CSS Line Clamp
/**
* CSS Line Clamp
*
* @example scss
* @include line-clamp(2, 16, 1.5)
*
* @param {Integer} $lines: number of lines to show
* @param {Integer} $font-size: font size in px (no trailing 'px'!)
* @param {Integer} $line-height: line height (multiplier/unitless)
*/
@mixin line-clamp($lines, $font-size, $line-height) {
-webkit-box-orient: vertical;
-webkit-line-clamp: $lines;
display: -webkit-box;
height: #{$lines * ( $font-size / 16 ) * $line-height}em;
padding: 0;
text-overflow: ellipsis;
text-overflow: -o-ellipsis-lastline; // old Opera
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment