Why using absolute position causes the div to be on top?

后端 未结 3 824
庸人自扰
庸人自扰 2020-12-04 03:27

Please see this very simple snippet to illustrate my question below:

3条回答
  •  一向
    一向 (楼主)
    2020-12-04 04:05

    The top, right, bottom, left, and z-index properties have no effect for position: static which is the default value for elements, in your case which h1 tag is. When position is set to relative it creates a new stacking context when the value of z-index is other than auto.

    For more read on stacking context:

    https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context

提交回复
热议问题