z-index controls the stack order of elements along the z-axis (which element appears “on top”).
Only elements with a position value other than static can use z-index.
z-index controls the stack order of elements along the z-axis (which element appears “on top”).
Only elements with a position value other than static can use z-index.
.blue { z-index: 1; }
.red { z-index: 2; }
.green { z-index: 3; }
Higher z-index = on top.
.behind { z-index: -1; }
.parent { transform: translateZ(0); } /* new context */
.child { z-index: 999; } /* limited inside parent */
Even with z:999, the child cannot overlap the outside element because it’s trapped in its parent’s stacking context.
Tips for using z-index:
position with z-index, opacity < 1, transform, filter, etc.