Skip to content

Instantly share code, notes, and snippets.

@splatio
Last active December 12, 2015 00:09
Show Gist options
  • Save splatio/4682015 to your computer and use it in GitHub Desktop.
Save splatio/4682015 to your computer and use it in GitHub Desktop.
Scss mixin inspired by http://cssarrowplease.com
@mixin arrow($position, $size, $color, $border-size: 0, $border-color: transparent) {
// Box we're adding the arrow to.
position: relative;
background: $color;
@if $border-size != 0 {
border: $border-size solid $border-color;
}
// Swap the position around to the position we actually need.
$center-position: left;
@if $position == top {
$position: bottom;
} @else if $position == right {
$position: left;
$center-position: top;
} @else if $position == bottom {
$position: top;
} @else if $position == left {
$position: right;
$center-position: top;
}
// Main arrow and border arrow.
@if $border-size == 0 {
&:after, &:before {
#{$position}: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
} @else {
&:after, &:before {
#{$position}: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
}
// Main Arrow
&:after {
border-color: transparent;
border-#{$position}-color: $color;
border-width: $size;
#{$center-position}: 50%;
margin-left: -$size;
}
// Border arrow.
@if $border-size != 0 {
&:before {
border-color: transparent;
border-#{$position}-color: $border-color;
border-width: $size + round($border-size * 1.41421356);
#{$center-position}: 50%;
margin-left: -(round(($size + ($border-size * 1.41421356))));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment