Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Add z-index tool #13

Open
hatzipanis opened this issue Dec 29, 2017 · 1 comment
Open

Add z-index tool #13

hatzipanis opened this issue Dec 29, 2017 · 1 comment

Comments

@hatzipanis
Copy link
Member

@function z($layer) {
    @if not map-has-key($z-layers, $layer) {
        @error "No layer found for `#{$layer}` in $z-layers map.";
    }
    @return map-get($z-layers, $layer);
}

$z-layers: (
    'example'  : 9999,
);

.example {
    z-index: z(example);
}
@hatzipanis
Copy link
Member Author

I also stumbled across the following approach when reading this.

// z-index.scss
$z-index:
    $header,
    $side-nav,
    $chat-window,
    $drop-down-menu,
    $full-screen-modal;
// Usage:
// z-index: index($z-index, nameOfKey);
// sidenav.scss or whatever
.side-nav {
    position: relative;
    z-index: index($z-index, side-nav);
}

That way you don’t have to update all your z-index values when you find something needs to be in between $header and $side-nav. You just rearrange the ordered list and your processed/compiled values will update accordingly. You also get the added benefit of seeing what components are higher than others from a birds eye view.

Thoughts? That article also mentions z-index stacking contexts which I actually never knew existed. Worth a read.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant