-
-
Save superfine/802b84e236e8ab2e6b251f74ecbc4bd6 to your computer and use it in GitHub Desktop.
Recursive z-index management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see the original medium post: https://medium.com/alistapart/sassier-z-index-management-for-complex-layouts-4540717a9488