Skip to content

Instantly share code, notes, and snippets.

@drementer
Last active June 18, 2022 10:00
Show Gist options
  • Save drementer/131d8df5109952f1905f3bad3a8a552a to your computer and use it in GitHub Desktop.
Save drementer/131d8df5109952f1905f3bad3a8a552a to your computer and use it in GitHub Desktop.
Scss Text Truncate Mixin
/// Truncate
/// Sets the maximum number of rows the element will have
/// If the maximum line is exceeded, cut off the excess lines.
/// puts "..." at the end of the last line
/// @param {number} $max-line [2] - max line of paragraph
/// @example scss - truncate mixin
/// .text {
/// @include truncate(2);
/// }
@mixin truncate($max-line: 2) {
display: -webkit-box;
-webkit-line-clamp: $max-line;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
@drementer
Copy link
Author

Also, if the text you cut has a padding value, replace it with a margin or remove it.

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