Skip to content

Instantly share code, notes, and snippets.

@sharjeel619
Created May 14, 2019 22:33
Show Gist options
  • Save sharjeel619/1f6c095ed4fc227a5c1866ef62f75c77 to your computer and use it in GitHub Desktop.
Save sharjeel619/1f6c095ed4fc227a5c1866ef62f75c77 to your computer and use it in GitHub Desktop.
Line Truncate with ellipses at the end.
/* Simple css way to truncate line with ellipses at the end. Doesn't work with IE & Firefox*/
:root {
--lines-to-show: 3;
--line-height: 18px;
--font-size: 16px;
}
.element-to-truncate {
display: block;
display: -webkit-box;
max-width: 100%;
max-height: calc(var(--line-height) * var(--lines-to-show)); /* line height * lines to show; */
font-size: var(--font-size);
line-height: var(--line-height);
-webkit-line-clamp: var(--lines-to-show);
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
/* A mixin in SCSS. Doesn't work with IE & Firefox */
@mixin lineTruncate($font-size, $line-height, $lines-to-show) {
display: block;
display: -webkit-box;
max-width: 100%;
max-height: $line-height * $lines-to-show;
font-size: $font-size;
line-height: $line-height;
-webkit-line-clamp: $lines-to-show;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment