Last active
February 6, 2017 12:54
-
-
Save teyepe/ed84919941a27f16a75a521c6f8594f4 to your computer and use it in GitHub Desktop.
Sass z-index function
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-index: ( | |
'under': -5, | |
'zero': 0, | |
'default': 5, | |
'over': 10 | |
); | |
$z-level: ( | |
'footer': 20, | |
'header': 30, | |
'tooltip': 100, | |
'dropdown': 200, | |
'modal': 500 | |
); | |
$z-combo: map-merge($z-index, $z-level); | |
@function z($index: null, $level: null) { | |
@if $index and map-has-key($z-combo, $level) { | |
@return map-get($z-combo, $index) + map-get($z-combo, $level); | |
} | |
@else if $index == auto and $level == null { | |
@return auto; | |
} | |
@else if $index == null and $level == null { | |
@return auto; | |
} | |
@else if $index == null and $level { | |
@return map-get($z-combo, $level); | |
} | |
@else if $index == $level and $level == null map-has-key($z-combo, $index) { | |
@return map-get($z-combo, $index); | |
} | |
} | |
// examples | |
.index { | |
z-index: z(over); | |
} | |
.index-level { | |
z-index: z(dropdown, under); | |
} | |
.null-level { | |
z-index: z(null, dropdown); | |
} | |
.level { | |
z-index: (z(dropdown) + z(default)*4); | |
} | |
.auto { | |
z-index: z(auto); | |
} | |
.null { | |
z-index: z(); | |
} |
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
.index { | |
z-index: 10; | |
} | |
.index-level { | |
z-index: 195; | |
} | |
.null-level { | |
z-index: 200; | |
} | |
.level { | |
z-index: 220; | |
} | |
.auto { | |
z-index: auto; | |
} | |
.null { | |
z-index: auto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment