Created
May 14, 2019 22:33
-
-
Save sharjeel619/1f6c095ed4fc227a5c1866ef62f75c77 to your computer and use it in GitHub Desktop.
Line Truncate with ellipses at the end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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