Created
December 11, 2015 16:32
-
-
Save thomasthesecond/00c1422e1e90895ed437 to your computer and use it in GitHub Desktop.
This file contains 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
/// Clamps, aka truncates, multi-line text. Note that non-webkit browsers will | |
/// not see the ellipsis ¯\_(ツ)_/¯ | |
/// @param {Value} $font-size - Font size of the text | |
/// @param {Unitless Value} $line-height - Line height of the text; **must be a unitless value** | |
/// @param {Number} $lines-to-show - Number of lines to show | |
/// @example scss | |
/// p { | |
/// @include line-clamp($font-size: 16px, $line-height: 1.5, $lines-to-show: 3); | |
/// } | |
@mixin line-clamp( | |
$font-size, | |
$line-height, | |
$lines-to-show | |
) { | |
@if unitless($line-height) == false { | |
$line-height: create-unitless-line-height($font-size, $line-height); | |
} | |
display: block; // Fallback for non-webkit browsers | |
display: -webkit-box; | |
font-size: $font-size; | |
height: ($font-size * $line-height * $lines-to-show); // Fallback for non-webkit browsers | |
line-height: $line-height; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
-webkit-box-orient: vertical; | |
-webkit-line-clamp: $lines-to-show; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks for sharing this. Are you still using this mixin or made any updates?
I was wondering if you could share the function
create-unitless-line-height
?Have a great rest of your weekend!
Best