Created
May 7, 2018 10:27
-
-
Save klepas/4f877bfb9dfba09131b0ac91944a5990 to your computer and use it in GitHub Desktop.
Sass CSS truncation mixin
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
/// Truncate text mixin. | |
/// | |
/// Expected usage: (visually) truncate text. | |
/// | |
/// To avoid vertical alignment issues, we set the parent block to | |
/// display: inline-flex; therefore call this mixin on a parent block. | |
/// | |
/// @param {keywords} $width ['300px'] | |
/// | |
/// @output Sets rules for truncating text | |
/// | |
@mixin truncate($width: 300px) { | |
display: inline-flex; | |
> * { | |
display: inline-block; | |
max-width: $width; // This could be any CSS unit… eg, em, %, etc. | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; // Change as desired. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment