z-index not working with fixed positioning

后端 未结 8 1181
广开言路
广开言路 2020-11-22 03:46

I have a div with default positioning (i.e. position:static) and a div with a fixed position.

If I set the z-index

8条回答
  •  太阳男子
    2020-11-22 04:31

    Give the #under a negative z-index, e.g. -1

    This happens because the z-index property is ignored in position: static;, which happens to be the default value; so in the CSS code you wrote, z-index is 1 for both elements no matter how high you set it in #over.

    By giving #under a negative value, it will be behind any z-index: 1; element, i.e. #over.

提交回复
热议问题