Why does z-index not work?

前端 未结 5 1487
无人共我
无人共我 2020-11-21 05:39

So if I understand z-index correctly, it would be perfect in this situation:

\"enter

5条回答
  •  渐次进展
    2020-11-21 06:10

    Make sure that this element you would like to control with z-index does not have a parent with z-index property, because element is in a lower stacking context due to its parent’s z-index level.

    Here's an example:

    // CSS // .content { position: relative; z-index: 1; } .modal { position: fixed; z-index: 100; } .side-tab { position: fixed; z-index: 5; }

    In the example above, the modal has a higher z-index than the content, although the content will appear on top of the modal because "content" is the parent with a z-index property.

    Here's an article that explains 4 reasons why z-index might not work: https://coder-coder.com/z-index-isnt-working/

提交回复
热议问题