Skip to content

Instantly share code, notes, and snippets.

@shotasenga
Created September 8, 2016 23:13
Show Gist options
  • Save shotasenga/eb692704a46602f2192aa1a2a1fced5d to your computer and use it in GitHub Desktop.
Save shotasenga/eb692704a46602f2192aa1a2a1fced5d to your computer and use it in GitHub Desktop.
Sass positioning mixin
/*
posiitoning utility
*/
/**
* Set position and top, left, ...
* @prop {string} $position
* @prop {=number} $top
* @prop {=number} $right
* @prop {=number} $bottom
* @prop {=number} $left
*
* ex. position(absolute, 0 10px)
*/
@mixin position ($position, $args: ()) {
position: $position;
@debug $args;
@if length($args) == 1 {
$n: nth($args, 1);
$args: join($args, $n $n $n);
} @else if length($args) == 2 {
$args: join($args, $args);
} @else if length($args) == 3 {
$args: join($args, nth($args, 2));
}
@if length($args) > 0 {
$positions: zip(top right bottom left, $args);
@each $key, $value in $positions {
@if $value != null {
#{$key}: $value;
}
}
}
}
/**
* Aliase for each positions
*/
@mixin static ($args: ()) {
@include position(static, $args);
}
@mixin relative ($args: ()) {
@include position(relative, $args);
}
@mixin absolute ($args: ()) {
@include position(absolute, $args);
}
@mixin sticky ($args: ()) {
@include position(sticky, $args);
}
@mixin fixed ($args: ()) {
@include position(fixed, $args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment