View the demo on CodePen.
Last active
December 25, 2015 02:29
-
-
Save andrewjtait/6902586 to your computer and use it in GitHub Desktop.
Arrow Sass Mixin
This file contains hidden or 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
<div class="down-arrow"></div> | |
<div class="up-arrow"></div> | |
<div class="left-arrow"></div> | |
<div class="right-arrow"></div> |
This file contains hidden or 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 arrow($direction, $size, $color) { | |
content: ""; // ensures the arrows are visible | |
// ensures the size of the arrows is correct: | |
width: 0; | |
height: 0; | |
// Lists for positions/directions | |
$directions: ('down', 'left', 'up', 'right'); | |
$positions: ('top', 'right', 'bottom', 'left'); | |
// Loop through each position | |
@each $position in $positions { | |
// Calculate the index of the position in the list | |
$index: index($positions, $position); | |
// If the position matches the direction, render a colored border | |
@if nth($directions, $index) == $direction { | |
border-#{$position}: $size solid $color; | |
} @else { | |
border-#{$position}: $size solid transparent; | |
} | |
} | |
} | |
// examples: | |
.down-arrow { | |
@include arrow(down, 50px, black); | |
} | |
.up-arrow { | |
@include arrow(up, 20px, black); | |
} | |
.left-arrow { | |
@include arrow(left, 10px, black); | |
} | |
.right-arrow { | |
@include arrow(right, 5px, black); | |
} | |
div { | |
float: left; | |
margin: 20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment