How to reverse the order of nested child elements

后端 未结 1 580
鱼传尺愫
鱼传尺愫 2020-12-12 04:02

Suppose I have the following HTML Code

HTML

相关标签:
1条回答
  • 2020-12-12 05:00

    You can't. The parent will always be behind the children, as z-index values are stacked.

    The order in which the rendering tree is painted onto the canvas is described in terms of stacking contexts. Stacking contexts can contain further stacking contexts. A stacking context is atomic from the point of view of its parent stacking context; boxes in other stacking contexts may not come between any of its boxes. - W3 http://www.w3.org/TR/CSS2/visuren.html#z-index

    By setting a z-index on .a, you are also setting the same z-index on all the children. For instance, by setting z-index:999 on .a -- .b, and .c now also have the same indexes, rending it useless. To achieve this, the elements cannot be a parent nor a child of another, they would have to be siblings for this to work.

    Here is what it would look like if they are siblings - it works!

    0 讨论(0)
提交回复
热议问题