Skip to content

Instantly share code, notes, and snippets.

@cocopon
Last active December 14, 2015 10:49
Show Gist options
  • Save cocopon/5074659 to your computer and use it in GitHub Desktop.
Save cocopon/5074659 to your computer and use it in GitHub Desktop.
Sass functions that extract a specified edge
// Example:
//
// $padding: 1px 2px 3px;
// top($padding) ...... 1px
// right($padding) .... 2px
// bottom($padding) ... 3px
// left($padding) ..... 2px
@function top($args) {
$len: length($args);
@if ($len >= 1 and $len <= 4) {@return nth($args, 1);}
}
@function right($args) {
$len: length($args);
@if ($len == 1) {@return nth($args, 1);}
@if ($len == 2) {@return nth($args, 2);}
@if ($len == 3) {@return nth($args, 2);}
@if ($len == 4) {@return nth($args, 2);}
}
@function bottom($args) {
$len: length($args);
@if ($len == 1) {@return nth($args, 1);}
@if ($len == 2) {@return nth($args, 1);}
@if ($len == 3) {@return nth($args, 3);}
@if ($len == 4) {@return nth($args, 3);}
}
@function left($args) {
$len: length($args);
@if ($len == 1) {@return nth($args, 1);}
@if ($len == 2) {@return nth($args, 2);}
@if ($len == 3) {@return nth($args, 2);}
@if ($len == 4) {@return nth($args, 4);}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment