Skip to content

Instantly share code, notes, and snippets.

@schjetne
Created June 12, 2014 11:33
Show Gist options
  • Save schjetne/da2198d2ac1d1aea3f06 to your computer and use it in GitHub Desktop.
Save schjetne/da2198d2ac1d1aea3f06 to your computer and use it in GitHub Desktop.
@mixin spacer(10px 2em 100vh, margin, 4);
@mixin spacer($val, $type:'padding', $scale: 2) {
// Usage:
// @include spacer(10px 2em 100vh, margin, 4);
// or
// @include spacer(10px 2em 100vh);
@if $val != 0 and $val != false {
$keys: top left bottom right;
$vals: 0 0 0 0;
@if length($val) == 1 {
$vals: $val $val $val $val;
} @else if length($val) == 2 {
$vals: nth($val, 1) nth($val, 2) nth($val, 1) nth($val, 2);
} @else if length($val) == 3 {
$vals: nth($val, 1) nth($val, 2) nth($val, 3) nth($val, 2);
} @else if length($val) > 3 {
$vals: nth($val, 1) nth($val, 2) nth($val, 3) nth($val, 4);
}
@for $i from 1 through 4 {
@if nth($vals, $i) != 0 {
#{$type}-#{nth($keys, $i)}: nth($vals, $i);
}
}
@media (max-width: $small) {
@for $i from 1 through 4 {
@if nth($vals, $i) != 0 {
#{$type}-#{nth($keys, $i)}: nth($vals, $i) / $scale;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment