Last active
December 21, 2015 06:09
-
-
Save dalgard/6262098 to your computer and use it in GitHub Desktop.
A Sass mixin for setting position the same way that margin and padding are set (`null` is used where no value should be output)
This file contains 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
/* | |
Set position like margin/padding shorthand - rules with null value | |
are removed from output (standard) | |
Example: | |
@include position(0 20px null, fixed); | |
Output: | |
position: fixed; | |
top: 0; | |
left: 20px; | |
right: 20px; | |
*/ | |
@mixin position($coordinates: 0, $position: absolute) { | |
$length: length($coordinates); | |
$top: nth($coordinates, 1); | |
$right: nth($coordinates, 1); | |
$bottom: nth($coordinates, 1); | |
$left: nth($coordinates, 1); | |
@if $length > 1 { | |
$right: nth($coordinates, 2); | |
$left: nth($coordinates, 2); | |
} | |
@if $length > 2 { $bottom: nth($coordinates, 3); } | |
@if $length > 3 { $left: nth($coordinates, 4); } | |
position: $position; | |
top: $top; | |
bottom: $bottom; | |
left: $left; | |
right: $right; | |
} |
Author
dalgard
commented
Feb 18, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment