Source : Smashing Mag
Created
June 18, 2014 13:09
-
-
Save Plou/8a184022f208ef6cdc3d to your computer and use it in GitHub Desktop.
Smart z-index management with SASS
This file contains hidden or 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($list, $element) { | |
| $z-index: index($list, $element); | |
| @if $z-index { | |
| @return $z-index; | |
| } | |
| @warn 'There is no item "#{$element}" in this list; choose one of: #{$list}'; | |
| @return null; | |
| } |
This file contains hidden or 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
| .covers { | |
| z-index: 1; | |
| } | |
| .tooltip { | |
| z-index: 2; | |
| } | |
| .sorting-bar { | |
| z-index: 3; | |
| } | |
| .modals { | |
| z-index: 4; | |
| } | |
| .navigation { | |
| z-index: 5; | |
| } | |
| .covers-inherit { | |
| z-index: 1; | |
| } | |
| .modals-inherit { | |
| z-index: 4; | |
| } |
This file contains hidden or 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
| // # Usage | |
| // ## Stack order declaration | |
| $elements: covers, tooltip, sorting-bar, modals, navigation; | |
| // ## Automatic generation | |
| @each $element in $elements { | |
| .#{$element} { | |
| z-index: z($elements, $element); | |
| } | |
| } | |
| // ## Application to elements | |
| .covers-inherit { | |
| z-index: z($elements, covers); // .project-covers {z-index: 1; } | |
| } | |
| .modals-inherit { | |
| z-index: z($elements, modals); // .project-covers {z-index: 4; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment