Z-index management with SCSS
// Set our z-indexes map
$z-indexes: (
"up-btn",
//60
"cookies-info",
//50
"left-nav",
//40
"footer",
//30
"top-nav",
//20
"content",
//10
);
// Z function return the z-index value
@function z($name) {
@if index($z-indexes, $name) {
@return ((length($z-indexes) - index($z-indexes, $name)) + 1) * 10;
} @else {
@warn 'There is no item "#{$name}" in this list; choose one of: #{$z-indexes}';
@return null;
}
}
//------
.content {
z-index: z("content");
}
.img-1 {
z-index: z("content") + 2;
}
.img-2 {
z-index: z("content") + 1;
}
.top-nav {
z-index: z("top-nav");
}
.mkt-flash {
z-index: z("top-nav") - 1;
}
.left-nav {
z-index: z("left-nav");
}
.footer {
z-index: z("footer");
}
.cookies-info {
z-index: z("cookies-info");
}
.up-btn {
z-index: z("up-btn");
}
Example
See the Pen z-index Sass management by Vincent Humeau (@vinceumo) on CodePen.