Created
June 17, 2014 03:24
-
-
Save athaeryn/f2eec2aadf83064e792d to your computer and use it in GitHub Desktop.
Sass mixin for z-index
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
// ---- | |
// Sass (v3.3.8) | |
// Compass (v1.0.0.alpha.19) | |
// ---- | |
/* | |
* inspired by: | |
* http://www.smashingmagazine.com/2014/06/12/sassy-z-index-management-for-complex-layouts/ | |
*/ | |
$z: ( | |
base: | |
project-covers | |
user-tooltip | |
sorting-bar | |
modals | |
navigation | |
, | |
modals: | |
fields | |
form-controls | |
errors | |
autocomplete-dropdown | |
); | |
@function single($x) { | |
@return length($x) == 1; | |
} | |
@function first($x) { | |
@return nth($x, 1); | |
} | |
@function last($x) { | |
@return nth($x, length($x)); | |
} | |
@mixin z-index($component) { | |
$layer: if(single($component), base, first($component)); | |
z-index: index(map-get($z, $layer), last($component)); | |
} | |
#nav { | |
@include z-index(navigation); | |
} | |
#modal { | |
@include z-index(modals); | |
} | |
#modal__error { | |
@include z-index(modals form-controls); | |
} |
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
/* | |
* inspired by: | |
* http://www.smashingmagazine.com/2014/06/12/sassy-z-index-management-for-complex-layouts/ | |
*/ | |
#nav { | |
z-index: 5; | |
} | |
#modal { | |
z-index: 4; | |
} | |
#modal__error { | |
z-index: 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment