Skip to content

Instantly share code, notes, and snippets.

@ralexandr
Last active October 19, 2016 09:17
Show Gist options
  • Save ralexandr/1738628ce08ced78d4d0381551211e4e to your computer and use it in GitHub Desktop.
Save ralexandr/1738628ce08ced78d4d0381551211e4e to your computer and use it in GitHub Desktop.
SASS: triangles
/*--------------------------------
CSS Triangle
used for creating CSS only triangles
example:
.element {
&::before {
@include css-triangle(blue, down);
}
}
*/
@mixin css-triangle($color, $direction, $size: 6px, $position: absolute, $round: false){
@include pseudo($pos: $position);
width: 0;
height: 0;
@if $round {
border-radius: 3px;
}
@if $direction == down {
border-left: $size solid transparent;
border-right: $size solid transparent;
border-top: $size solid $color;
margin-top: 0 - round( $size / 2.5 );
} @else if $direction == up {
border-left: $size solid transparent;
border-right: $size solid transparent;
border-bottom: $size solid $color;
margin-bottom: 0 - round( $size / 2.5 );
} @else if $direction == right {
border-top: $size solid transparent;
border-bottom: $size solid transparent;
border-left: $size solid $color;
margin-right: -$size;
} @else if $direction == left {
border-top: $size solid transparent;
border-bottom: $size solid transparent;
border-right: $size solid $color;
margin-left: -$size;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment