Skip to content

Instantly share code, notes, and snippets.

@nathanaelnsmith
Last active October 13, 2015 15:47
Show Gist options
  • Save nathanaelnsmith/4218632 to your computer and use it in GitHub Desktop.
Save nathanaelnsmith/4218632 to your computer and use it in GitHub Desktop.
A Less / Sass Mixin that creates triangles for :before and :after pseudo elements
#triangle {
.bottom(@color:#5c82bb,@height:5px,@width:4px) {
width: 0;
height: 0;
border-top: @height solid @color;
border-left: @width solid transparent;
border-right: @width solid transparent;
}
.bottom-right(@color:#5c82bb,@height:5px,@width:4px) {
width: 0;
height: 0;
border-bottom: @height solid @color;
border-left: @width solid transparent;
}
.left(@color:#5c82bb,@height:5px,@width:4px) {
width: 0;
height: 0;
border-top: @height solid transparent;
border-bottom: @height solid transparent;
border-right: @width solid @color;
}
}
@mixin triangle ($direction, $color, $height, $width) {
width: 0;
height: 0;
@if $direction == 'bottom' {
border-top: $height solid $color;
border-left: $width solid transparent;
border-right: $width solid transparent;
}
@if $direction == 'bottom-right' {
width: 0;
height: 0;
border-bottom: $height solid $color;
border-left: $width solid transparent;
}
@if $direction == 'left' {
border-top: $height solid transparent;
border-bottom: $height solid transparent;
border-right: $width solid $color;
}
@if $direction == 'right' {
border-top: $height solid transparent;
border-bottom: $height solid transparent;
border-left: $width solid $color;
}
@if $direction == 'top' {
border-bottom: $height solid $color;
border-left: $width solid transparent;
border-right: $width solid transparent;
}
@if $direction == 'top-left' {
width: 0;
height: 0;
border-top: $height solid $color;
border-right: $width solid transparent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment