Skip to content

Instantly share code, notes, and snippets.

@rgkimball
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgkimball/a2e357bb11597f4f8f3a to your computer and use it in GitHub Desktop.
Save rgkimball/a2e357bb11597f4f8f3a to your computer and use it in GitHub Desktop.
This is an extremely lightweight mixin for adding CSS triangles to pseudo elements.
@mixin triangle($direction: "right", $size: 5px, $color: '#FFFFFF') {
@if not index(top right bottom left, $direction) {
@warn "\"#{$direction}\" is not a valid direction value. Value must be one of: top, right, bottom, left";
}
@else {
@include transform(scale(1.01)); // @see https://brettstrikesback.com/de-pixelating-the-css-triangle/
border: $size solid transparent;
border-#{$direction}-color: $color;
border-#{opposite-position($direction)}-width: 0;
#{opposite-position($direction)}: -$size;
content: '';
height: 0;
width: 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment