Skip to content

Instantly share code, notes, and snippets.

@tsi
Last active November 27, 2016 14:16
Show Gist options
  • Save tsi/4336728 to your computer and use it in GitHub Desktop.
Save tsi/4336728 to your computer and use it in GitHub Desktop.
Sass triangle
@mixin triangle(
$dir: top,
$pos: 50%,
$color1: #fff,
$color2: darken($color1, 30%),
$size1: 6px,
$size2: $size1
) {
$opos: map-get(( top: bottom, right: left, bottom: top, left: right ), $dir);
$transparent: if($dir == left or $dir == right, (top, bottom), (left, right));
&:before,
&:after {
#{nth($transparent, 1)}: $pos;
height: 0;
width: 0;
display: block;
content: " ";
position: absolute;
}
&:before {
border-#{nth($transparent, 1)}: #{$size2 + 1} solid transparent;
border-#{nth($transparent, 2)}: #{$size2 + 1} solid transparent;
border-#{$opos}: #{$size1 + 1} solid $color2;
margin-#{nth($transparent, 1)}: -1 - $size2;
#{$dir}: -1 - $size1;
}
&:after {
border-#{nth($transparent, 1)}: $size2 solid transparent;
border-#{nth($transparent, 2)}: $size2 solid transparent;
border-#{$opos}: $size1 solid $color1;
margin-#{nth($transparent, 1)}: - $size2;
#{$dir}: - $size1;
}
}
@tsi
Copy link
Author

tsi commented Dec 19, 2012

Usage:
@include triangle(top);
Will create a small triangle pointing up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment