Skip to content

Instantly share code, notes, and snippets.

@Xhamps
Created May 23, 2014 15:11
Show Gist options
  • Save Xhamps/7d0dd1ad626a6ead2c8e to your computer and use it in GitHub Desktop.
Save Xhamps/7d0dd1ad626a6ead2c8e to your computer and use it in GitHub Desktop.
Mixin Position
@mixin absolute($args) {
/**
* List of offsets to check for in $args
*/
$offsets: top right bottom left;
/**
* We loop through $offsets to deal with them one by one
*/
@each $o in $offsets {
/**
* If current offset found in $args
* assigns its index to $i
* Or `false` if not found
*/
$i: index($args, $o);
/**
* Now we do the verifications
* 1. Is the offset listed in $args? (not false)
* 2. Is the offset value within the list range?
* 3. Is the offset value valid?
*/
@if $i /* 1 */
and $i + 1 <= length($args) /* 2 */
and type-of( nth($args, $i + 1) ) == number /* 3 */ {
/**
* If everything is okay
* We assign the according value to the current offset
*/
#{$o}: nth($args, $i + 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment