CSS: Filling the Gaps 4 (Stacking Context)
An HTML document may seem like a flat plane, but in reality, HTML elements exist in three dimensions. That is, in addition to the X and Y axes, there is also the Z axis.
A stacking context in the document is formed by any element that meets any one of the following conditions:
The document root element (
<html>);Elements with
positionset toabsoluteorrelativeand az-indexvalue other thanauto;Elements with
positionset tofixed(fixed positioning) orsticky(sticky positioning);Children of a flex or grid container, with a
z-indexvalue other thanauto;Elements with an
opacityvalue less than1(see the specification for opacity);Elements with any of the following properties set to a value other than
none:transformfilterbackdrop-filterperspectiveclip-pathmask/mask-image/mask-border
Elements with
isolationset toisolate;Elements whose
will-changevalue specifies a property that creates a stacking context when set to a non-initial value (refer to this article);Elements with
containset tolayout,paint, or a composite value that includes one of them (e.g.,contain: strict,contain: content).
The z-index value of a child stacking context only makes sense within its parent.