z-index inherits parents z-index , or not?

前端 未结 3 1607
我寻月下人不归
我寻月下人不归 2020-12-31 07:03

I have two absolute divs. One item on div A will show div B (on click + some javascript code). I want to have a higher Zindex on B than on A. (I want B above A)-

Thi

3条回答
  •  遥遥无期
    2020-12-31 07:34

    you say:

    absolute divs

    EDIT

    from w3.org spec

    absolute

    Only works on positioned elements(position: absolute;, position: relative; or position: fixed;).

    Visual formatting model

    he 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. Each box belongs to one stacking context. Each positioned box in a given stacking context has an integer stack level, which is its position on the z-axis relative other stack levels within the same stacking context. Boxes with greater stack levels are always formatted in front of boxes with lower stack levels. Boxes may have negative stack levels. Boxes with the same stack level in a stacking context are stacked back-to-front according to document tree order. The root element forms the root stacking context. Other stacking contexts are generated by any positioned element (including relatively positioned elements) having a computed value of 'z-index' other than 'auto'. Stacking contexts are not necessarily related to containing blocks.

    Anyway, as already mentioned, you can test z-index of your div by

    window.getComputedStyle(element)
    

提交回复
热议问题