Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Last active May 30, 2017 02:14
Show Gist options
  • Save benjamincharity/0e6f121fad1bfa65508d5b7523163e3d to your computer and use it in GitHub Desktop.
Save benjamincharity/0e6f121fad1bfa65508d5b7523163e3d to your computer and use it in GitHub Desktop.
Determine z-index based off of a list. This allows new items to be added without needing a refactor.
$z-layers: (
"header",
"menu",
"menu-trigger",
);
/////////////////////////////////////////////
//
// Determine the correct z-index
//
@function z($name) {
@if index($z-layers, $name) {
@return (length($z-layers) - index($z-layers, $name)) + 1;
} @else {
@warn 'There is no item "#{$name}" in this list; choose one of: #{$z-layers}';
@return null;
}
}
// Use
.foo {
z-index: z('header');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment