Last active
September 20, 2016 10:33
-
-
Save junaidbhura/6436e47b7c30687d136df7cbe1c346f3 to your computer and use it in GitHub Desktop.
Sass (SCSS) Mixin to create CSS triangles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin css-triangle( $width: 11px, $height: 7px, $color: '#000', $direction: 'down' ) { | |
width: 0; | |
height: 0; | |
border-style: solid; | |
@if ( $direction == 'down' ) { | |
$half-width: $width / 2; | |
border-width: $height $half-width 0 $half-width; | |
border-color: $color transparent transparent transparent; | |
} | |
@else if ( $direction == 'up' ) { | |
$half-width: $width / 2; | |
border-width: 0 $half-width $height $half-width; | |
border-color: transparent transparent $color transparent; | |
} | |
@else if ( $direction == 'left' ) { | |
$half-height: $height / 2; | |
border-width: $half-height $width $half-height 0; | |
border-color: transparent $color transparent transparent; | |
} | |
@else if ( $direction == 'right' ) { | |
$half-height: $height / 2; | |
border-width: $half-height 0 $half-height $width; | |
border-color: transparent transparent transparent $color; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: @include css-triangle( 11px, 7px, #8A74B9, 'down' );