Overlapping items

Unlike flexbox, in grid several items can occupy the same cells. This lets you create overlaps without using position: absolute.
  • Assign items the same row and column lines, fully or partially.
  • By default, the last item in the HTML is painted on top.
  • With z-index you control the stacking order without needing position.
  • Assigning grid-area: 1 / 1 to several children is a simple pattern for stacking image and text.

Example

The two items share grid cells. Change the z-index value on the item class to decide which one stays in front.

Select z-index:
ResultLive
html
css