Skip to content

Instantly share code, notes, and snippets.

@czajkovsky
Last active August 29, 2015 14:04
Show Gist options
  • Save czajkovsky/dc9c93467b92e1d05e75 to your computer and use it in GitHub Desktop.
Save czajkovsky/dc9c93467b92e1d05e75 to your computer and use it in GitHub Desktop.
@mixin position_parser($values) {
$dirs: (top, 1),
(right, 2),
(bottom, 3),
(left, 4);
@each $dir, $i in $dirs {
@if nth($values, $i) != null {
#{$dir}: nth($values, $i);
}
}
}
@mixin position($position, $args) {
position: $position;
@if length($args) == 1 {
@include position_parser($args $args $args $args);
}
@else if length($args) == 2 {
@include position_parser(nth($args, 1) nth($args, 2) nth($args, 1) nth($args, 2));
}
@else if length($args) == 3 {
@include position_parser(nth($args, 1) nth($args, 2) nth($args, 1) null);
}
@else if length($args) == 4 {
@include position_parser($args);
}
}
@mixin absolute($args) {
@include position(absolute, $args);
}
@mixin relative($args) {
@include position(relative, $args);
}
@mixin fixed($args) {
@include position(fixed, $args);
}
.pos--1 {
@include absolute(5rem);
}
.pos--2 {
@include absolute(5rem 3rem);
}
.pos--3 {
@include absolute(5rem 3rem 4rem);
}
.pos--4 {
@include absolute(5rem 1rem 2rem 4rem);
}
.post--top-bottom {
@include absolute(5rem null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment