Skip to content

Instantly share code, notes, and snippets.

@krzysu
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzysu/71e5d96e00bec95bb4c7 to your computer and use it in GitHub Desktop.
Save krzysu/71e5d96e00bec95bb4c7 to your computer and use it in GitHub Desktop.
css arrow mixins (using border)
@mixin arrow($color, $width) {
display: block;
position: relative;
&:before,
&:after {
content: ' ';
border: solid transparent;
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
&:before {
border-width: $width;
}
&:after {
border-width: $width - 2;
}
}
@mixin arrow-top($color, $width, $bold: 'normal') {
@include arrow($color, $width);
width: $width * 2;
height: $width;
&:before,
&:after {
bottom: 50%;
left: 50%;
}
&:before {
border-bottom-color: $color;
margin-left: -$width;
margin-bottom: -$width/2;
}
&:after {
border-bottom-color: white;
margin-left: -($width - 2);
margin-bottom: -$width/2;
@if $bold == 'bold' {
margin-left: -1px;
}
}
}
@mixin arrow-right($color, $width, $bold: 'normal') {
@include arrow($color, $width);
width: $width;
height: $width * 2;
&:before,
&:after {
top: 50%;
left: 0%;
}
&:before {
border-left-color: $color;
margin-top: -$width;
}
&:after {
border-left-color: white;
margin-top: -($width - 2);
@if $bold == 'bold' {
margin-left: -1px;
}
}
}
@mixin arrow-bottom($color, $width, $bold: 'normal') {
@include arrow($color, $width);
width: $width * 2;
height: $width;
&:before,
&:after {
top: 50%;
left: 50%;
}
&:before {
border-top-color: $color;
margin-left: -$width;
margin-top: -$width/2;
}
&:after {
border-top-color: white;
margin-left: -($width - 2);
margin-top: -$width/2;
@if $bold == 'bold' {
margin-left: -1px;
}
}
}
@mixin arrow-left($color, $width, $bold: 'normal') {
@include arrow($color, $width);
width: $width;
height: $width * 2;
&:before,
&:after {
top: 50%;
right: 0%;
}
&:before {
border-right-color: $color;
margin-top: -$width;
}
&:after {
border-right-color: white;
margin-top: -($width - 2);
@if $bold == 'bold' {
margin-left: -1px;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment