The z-index property does not apply to all CSS properties that create a new stacking context. In fact, it only works with the following:
This means that, z-index will not work if an element does not have position other than static, or it's not a flex item or grid item.
Properties that create a new stacking context only affect the stacking order, blending, compositing, transformation, clipping, masking, and transparency of elements within that context. For z-index this means that, if z-index is applied to elements within a stacking context, their stacking order will be determined relative to the parent, isolated from elements outside the stacking context it is in.