Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active December 15, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miguelmota/5327822 to your computer and use it in GitHub Desktop.
Save miguelmota/5327822 to your computer and use it in GitHub Desktop.
Sass mixin to create a triangle. Blog post: http://www.miguelmota.com/blog/sass-triangles
//
// Sass mixin to create a triangle
//
@mixin triangle($size:24px, $color:#000, $direction:up, $trim:false, $transparent:false) {
content: "";
display: inline-block;
width: 0;
height: 0;
border: solid $size;
@if $direction == up {
border-color: transparent transparent $color transparent;
@if $transparent {
border-color: $color $color transparent $color;
}
@if $trim {
border-top-width: 0;
}
}
@if $direction == right {
border-color: transparent transparent transparent $color;
@if $transparent {
border-color: $color $color $color transparent ;
}
@if $trim {
border-right-width: 0;
}
}
@if $direction == down {
border-color: $color transparent transparent transparent;
@if $transparent {
border-color: transparent $color $color $color;
}
@if $trim {
border-bottom-width: 0;
}
}
@if $direction == left {
border-color: transparent $color transparent transparent;
@if $transparent {
border-color: $color transparent $color $color;
}
@if $trim {
border-left-width: 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment