Z-index Without Pain
Grid allows placing multiple elements in the same cell (or cell range). This is much simpler and more stable than position: absolute.
How to Implement:
You simply assign the same coordinates to different elements:
.item-1 { grid-column: 1 / 3; grid-row: 1 / 3; }
.item-2 { grid-column: 2 / 4; grid-row: 2 / 4; z-index: 2; }
Advantages:
- Adaptability: When grid changes, elements will move together, preserving overlay.
- Predictability: You don't need to worry about which parent is the " base " for coordinates.
Tip
Use overlay in grids to create modern effects where text " crawls " onto part of an image.