Skip to content

Instantly share code, notes, and snippets.

@Alecto
Last active November 19, 2024 14:28
Show Gist options
  • Select an option

  • Save Alecto/a60f8b246bad4fab349d52a213df1eae to your computer and use it in GitHub Desktop.

Select an option

Save Alecto/a60f8b246bad4fab349d52a213df1eae to your computer and use it in GitHub Desktop.
Scss mixins
// Reset margin, padding, and remove list-style from a list.
@mixin unlist($m: 0, $p: 0) {
margin: $m;
padding: $p;
list-style: none;
}
// Truncate single-line text with ellipsis if it overflows.
@mixin text-shorten {
overflow: hidden;
max-width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
}
// Truncate multiline text with ellipsis for a specific number of lines.
@mixin block-shorten($fz: 1rem, $lh: 1.5, $h: 70px, $l: 3) {
display: -webkit-box;
overflow: hidden;
height: $h;
font-size: $fz;
line-height: $fz * $lh;
-webkit-box-orient: vertical;
-webkit-line-clamp: $l;
}
// Disable text selection for an element.
@mixin unselectable {
user-select: none;
-webkit-touch-callout: none;
}
// Hide an element visually but keep it accessible for screen readers.
@mixin visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
white-space: nowrap;
clip-path: inset(100%);
clip: rect(0 0 0 0);
overflow: hidden;
}
// Apply absolute positioning with customizable offsets.
@mixin abs-position($top: 0, $right: 0, $bottom: 0, $left: 0) {
position: absolute;
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment