Skip to content

Instantly share code, notes, and snippets.

@justerror
Forked from kaelig/_text-clamp.scss
Created August 19, 2021 08:27
Show Gist options
  • Save justerror/e25ceb7eccf9089393f6cf568569cdd6 to your computer and use it in GitHub Desktop.
Save justerror/e25ceb7eccf9089393f6cf568569cdd6 to your computer and use it in GitHub Desktop.
// Clamps a block of text to a certain number of lines,
// followed by an ellipsis in Webkit and Blink based browsers
// Reference: http://dropshado.ws/post/1015351370/webkit-line-clamp
@mixin text-clamp($lines: 2, $line-height: false) {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: $lines;
// Fallback for non-Webkit browsers
// (won't show `…` at the end of the block)
@if $line-height {
max-height: $line-height * $lines * 1px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment