Skip to content

Instantly share code, notes, and snippets.

@markjohnson4
Forked from patocallaghan/css-triangle.scss
Last active December 29, 2015 03:39
Show Gist options
  • Save markjohnson4/7609548 to your computer and use it in GitHub Desktop.
Save markjohnson4/7609548 to your computer and use it in GitHub Desktop.
//==== Simple SCSS mixin to create CSS triangles
//==== Example: @include css-triangle ("up", 30px, 10px, #fff); This would make a wide/short triangle
@mixin css-triangle ($direction: "down", $size: 20px, $color: #000) {
width: 0;
height: 0;
border-left: $size solid #{setTriangleColor($direction, "left", $color)};
border-right: $size solid #{setTriangleColor($direction, "right", $color)};
border-bottom: $size solid #{setTriangleColor($direction, "bottom", $color)};
border-top: $size solid #{setTriangleColor($direction, "top", $color)};
}
//Utility function to return the relevant colour depending on what type of arrow it is
@function setTriangleColor($direction, $side, $color) {
@if $direction == "left" and $side == "right"
or $direction == "right" and $side == "left"
or $direction == "down" and $side == "top"
or $direction == "up" and $side == "bottom" {
@return $color
} @else {
@return "transparent";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment