Skip to content

Instantly share code, notes, and snippets.

@klepas
Created May 7, 2018 10:27
Show Gist options
  • Save klepas/4f877bfb9dfba09131b0ac91944a5990 to your computer and use it in GitHub Desktop.
Save klepas/4f877bfb9dfba09131b0ac91944a5990 to your computer and use it in GitHub Desktop.
Sass CSS truncation mixin
/// 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