Skip to content

Instantly share code, notes, and snippets.

@stowball
Last active November 7, 2022 16:06
Show Gist options
  • Save stowball/080e77b8831e57f275f2a906f4d66697 to your computer and use it in GitHub Desktop.
Save stowball/080e77b8831e57f275f2a906f4d66697 to your computer and use it in GitHub Desktop.
Recursive z-index managment
$z-indexes: (
main: (
above-inherit: (),
nested: (
low,
middle,
high
),
tooltip: ()
),
header: (),
toaster: ()
);
.main {
z-index: z(main);
}
.nested {
z-index: z(main, nested);
}
.high {
z-index: z(main, nested, high);
}
@function z-index($keys) {
$map: $z-indexes;
$found-index: null;
@each $key in $keys {
@if (type-of($map) == "map") {
$found-index: index(map-keys($map), $key);
$map: map-get($map, $key);
}
@else {
$found-index: index($map, $key);
}
}
@return $found-index;
}
@function z($keys...) {
@return z-index($keys);
}
@fredconv
Copy link

Hi

Nice function
but one small missing thing:

@function z($keys...) { @return z-index($keys); }

instead of

@function z($keys) { @return z-index($keys); }

@superfine
Copy link

Hi, I'm gonna use this now, please correct "managment" to "management" :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment