Using z-index to get div above another div

前端 未结 4 1823
囚心锁ツ
囚心锁ツ 2020-11-28 16:00

I want the div1 to be above div2. I try with z-index but it does not work.

I\'ve tried this code:

4条回答
  •  粉色の甜心
    2020-11-28 16:27

    z-index only applies to elements with a position other than static, so for example: relative, absolute, or fixed.

    div {
      width:100px;
      height: 100px;
      position:relative;
    }
    .div1 {
      background: red;
      z-index: 2;
    }
    .div2 {
      background: blue;
      margin-top: -15vh;
      z-index: 1
    }

提交回复
热议问题