Skip to content

Instantly share code, notes, and snippets.

@prdolmos
Created May 3, 2016 13:23
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 prdolmos/29aeadcc191bb4f782d338b67b23779a to your computer and use it in GitHub Desktop.
Save prdolmos/29aeadcc191bb4f782d338b67b23779a to your computer and use it in GitHub Desktop.
css arrow mixin with direction, border, and different nesting
@mixin css-arrow($direction, $arrow-width, $arrow-height, $arrow-left-offset, $arrow-color, $arrow-border-color, $arrow-border-width, $arrow-type: container) {
@if not index(top bottom, $direction) {
@error "Direction must be either `top` or `bottom`.";
}
@if not index(container child, $arrow-type) {
@error "Type must be either `container` or `child`. ";
}
$base-element: '&:before';
@if $arrow-type == child { $base-element: '&' }
#{$base-element}, &:after {
content: '';
position: absolute;
display: block;
#{$direction}: -$arrow-height;
@if $arrow-type == container {
left: $arrow-left-offset;
}
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: ($arrow-width / 2);
border-#{opposite-position($direction)}-width: $arrow-height;
border-#{$direction}-width: 0;
border-#{opposite-position($direction)}-color: $arrow-border-color;
}
&:after {
@if $arrow-type == container {
#{$direction}: (-$arrow-height) + $arrow-border-width;
} @else {
#{$direction}: $arrow-border-width;
left: -($arrow-width / 2);
}
border-#{opposite-position($direction)}-color: $arrow-color;
border-width: ($arrow-width / 2) - $arrow-border-width;
border-#{opposite-position($direction)}-width: ($arrow-height - $arrow-border-width);
border-#{$direction}-width: 0;
margin-left: $arrow-border-width;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment