Skip to content

Instantly share code, notes, and snippets.

@teyepe
Last active February 6, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teyepe/ed84919941a27f16a75a521c6f8594f4 to your computer and use it in GitHub Desktop.
Save teyepe/ed84919941a27f16a75a521c6f8594f4 to your computer and use it in GitHub Desktop.
Sass z-index function
$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();
}
.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