Difference between auto, 0, and no z-index?

前端 未结 5 750
温柔的废话
温柔的废话 2021-02-11 17:12

What is the difference between:

  1. z-index: auto
  2. z-index: 0
  3. no z-index at all

All the above sc

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-11 17:37

    z-index:0 is always the "default layer" (the layer in which all elements without an explicit z-index reside), and z-index:auto means: "Sets the stack order equal to its parent". Since all the children of a parent by default start in the "z-layer 0" - relative to their parent, then, in-affect, z-index:auto and z-index:0 means the same thing: they will both be in the same "layer", and their stacking order will be according to the default stacking rules, which you can see here.

提交回复
热议问题