Z-index cannot be compared between parent elements and child elements. Only z-indexes at the same level can be compared.
For example, <p id="test1"><p id="test3"></p></p> and <p id="test2"></p> The z-index of test1 and test2 at the same level can be compared, but the z-index of test2 and test3 cannot be compared no matter what, because test3 is always on the layer above test1, and only test1 and test2 can be compared
Only when the two elements are in the same parent container, since they are in the same stacking context, it makes sense to use z-index; the parent-child relationship will only be based on the default that the child element must be on top of the parent element (regardless of Other weird situations) to render. Of course, this is not necessarily impossible. There is another situation where the element will be at the top by default, that is, when its label is lower, something like this:
<p>我在下边</p>
<p>我在上边</p>
So sometimes it’s better to write the two tags in different positions. z-indexIt’s more suitable to show up when the “default situation” is not sure~
Thank you for the invitation~,
This kind of inclusion relationship should be like this
You can consider another way to solve the problem
Z-index cannot be compared between parent elements and child elements. Only z-indexes at the same level can be compared.
For example, <p id="test1"><p id="test3"></p></p> and <p id="test2"></p> The z-index of test1 and test2 at the same level can be compared, but the z-index of test2 and test3 cannot be compared no matter what, because test3 is always on the layer above test1, and only test1 and test2 can be compared
The parent element does not specify
z-index
, and the child elementz-index
is-1
.But this use case should be rare.
Thank you for the invitation.
Only when the two elements are in the same parent container, since they are in the same stacking context, it makes sense to use
z-index
; the parent-child relationship will only be based on the default that the child element must be on top of the parent element (regardless of Other weird situations) to render.Of course, this is not necessarily impossible. There is another situation where the element will be at the top by default, that is, when its label is lower, something like this:
So sometimes it’s better to write the two tags in different positions.
z-index
It’s more suitable to show up when the “default situation” is not sure~Above.