Skip to content

Instantly share code, notes, and snippets.

@simmo
Created September 6, 2017 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simmo/75795070e9beba74495a62f14e2edc40 to your computer and use it in GitHub Desktop.
Save simmo/75795070e9beba74495a62f14e2edc40 to your computer and use it in GitHub Desktop.
Ideas for absolute Sass helper
@mixin position($position, $args: null) {
$offsets: bottom left right top;
position: $position;
@if (type-of($args) == 'list') {
@each $offset in $offsets { // 3
$index: index($args, $offset); // 4
@if $index { // 5
@if $index == length($args) { // 6
#{$offset}: 0; // 7
}
@else { // 8
$next: nth($args, $index + 1); // 9
@if is-valid-length($next) { // 10
#{$offset}: $next; // 11
}
@else if index($offsets, $next) { // 12
#{$offset}: 0; // 13
}
@else { // 14
@warn "Invalid value `#{$next}` for offset `#{$offset}`."; // 15
}
}
}
}
}
@else if (type-of($args) == 'number') {
@each $offset in $offsets {
#{$offset}: $args;
}
}
}
@mixin absolute($args: null) {
@include position(absolute, $args);
}
.test {
@include absolute(left 10px bottom 0);
}
.test2 {
-ms-scroll-snap-type: proximity;
scroll-snap-type: mandatory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment