Z-Index Utilities
NuvoUI provides a comprehensive set of z-index utilities that help you control the stacking order of elements on your page. These utilities include both numerical values and semantic named levels for better readability.
Configuration
The z-index system is built on configurable variables:
Parent Selector
All z-index utilities are scoped under the VAR.$parent-selector
which can be configured.
Z-Index Values
The system uses a set of predefined z-index values:
Named Z-Index Levels
The system also provides semantic named levels for better readability:
Breakpoints
Responsive variants are based on these breakpoint values:
Basic Usage
Apply z-index values using the .z-{value}
utilities:
Numerical Z-Index Utilities
Use numerical z-index values for fine-grained control:
Named Z-Index Utilities
Use semantic named z-index levels for better readability and maintainability:
Auto Z-Index
Use z-auto
to reset to the browser's automatic stacking:
Responsive Z-Index
Apply different z-index values at different breakpoints by adding the @{breakpoint}
suffix:
Common UI Patterns
Dropdown Menus
Navigation Bar
Modal Dialog
Toast Notifications
Z-Index Utilities Reference Table
Numerical Z-Index Classes
Class | CSS Property | Description |
---|---|---|
.z-auto | z-index: auto | Browser determines stacking order |
.z-0 | z-index: 0 | Z-index of 0 |
.z-10 | z-index: 10 | Z-index of 10 |
.z-20 | z-index: 20 | Z-index of 20 |
.z-30 | z-index: 30 | Z-index of 30 |
.z-40 | z-index: 40 | Z-index of 40 |
.z-50 | z-index: 50 | Z-index of 50 |
.z-60 | z-index: 60 | Z-index of 60 |
.z-70 | z-index: 70 | Z-index of 70 |
.z-80 | z-index: 80 | Z-index of 80 |
.z-90 | z-index: 90 | Z-index of 90 |
.z-100 | z-index: 100 | Z-index of 100 |
.z-200 | z-index: 200 | Z-index of 200 |
.z-500 | z-index: 500 | Z-index of 500 |
.z-1000 | z-index: 1000 | Z-index of 1000 |
Named Z-Index Classes
Class | CSS Property | Description |
---|---|---|
.z-base | z-index: 0 | Base level (default stacking context) |
.z-hover | z-index: 10 | For hover states and active elements |
.z-dropdown | z-index: 100 | For dropdown menus and popovers |
.z-sticky | z-index: 200 | For sticky elements like headers |
.z-fixed | z-index: 300 | For fixed position elements |
.z-drawer | z-index: 400 | For slide-out drawers and side panels |
.z-modal | z-index: 500 | For modal dialog content |
.z-popover | z-index: 600 | For popovers and tooltips |
.z-tooltip | z-index: 700 | For tooltips |
.z-overlay | z-index: 800 | For modal backdrops and overlays |
.z-toast | z-index: 900 | For toast notifications |
.z-max | z-index: 9999 | Maximum z-index (for critical UI) |
Responsive Classes
Add @{breakpoint}
suffix to any z-index class to apply it at a specific breakpoint:
.z-10@sm
.z-dropdown@md
.z-sticky@lg
.z-overlay@xl
SCSS Mixins
NuvoUI provides a comprehensive set of z-index mixins for use in your SCSS:
Main Z-Index Mixin
Mixin | Parameters | Description |
---|---|---|
@include z-index($value) | $value : Z-index value or key | Sets z-index from predefined maps or direct value |
Named Z-Index Mixins
Mixin | Description |
---|---|
@include z-base | Sets z-index for base elements (0) |
@include z-hover | Sets z-index for hover states (10) |
@include z-dropdown | Sets z-index for dropdowns (100) |
@include z-sticky | Sets z-index for sticky elements (200) |
@include z-fixed | Sets z-index for fixed elements (300) |
@include z-overlay | Sets z-index for overlays (400) |
@include z-drawer | Sets z-index for drawers (500) |
@include z-modal | Sets z-index for modals (600) |
@include z-popover | Sets z-index for popovers (700) |
@include z-tooltip | Sets z-index for tooltips (800) |
@include z-toast | Sets z-index for toasts (900) |
@include z-max | Sets z-index to maximum value (9999) |
@include z-auto | Sets z-index to auto |
Example SCSS Usage
Best Practices
Consistent Z-Index Scale
- Use the named z-index values whenever possible for semantic meaning
- Stick to the predefined z-index scale to maintain consistency
- Avoid arbitrary values like
z-index: 99999
that can lead to "z-index wars"
Component-Based Approach
- Consider the UI component hierarchy when assigning z-index values
- Use the lowest possible z-index value needed for your use case
- Organize components into meaningful stacking layers:
- Content (z-base)
- UI controls (z-dropdown, z-sticky)
- Overlays and modals (z-overlay, z-modal)
- Notifications (z-toast)
Scoping Z-Index Contexts
Remember that z-index only works on positioned elements (position: relative, absolute, fixed, sticky) and within stacking contexts:
Responsive Considerations
- Use responsive z-index utilities when elements need different stacking order on different devices
- Consider how overlapping elements behave across different screen sizes