css z-index issue with nested elements

前端 未结 2 1679
野的像风
野的像风 2020-11-27 23:36

I have 3 HTML elements that I want to order on the z plane:

2条回答
  •  囚心锁ツ
    2020-11-28 00:17

    You can do this by adding z-index only to card class and placing the elements in absolute.

    .bank {
      width: 150px;
      background: red;
      height: 150px;
      position: absolute;
      top: 0;
      left: 0;
    }
    
    .card {
      width: 50px;
      background: black;
      height: 50px;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
    }
    
    .button {
      width: 100px;
      background: blue;
      height: 100px;
      position: absolute;
      top: 0;
      left: 0;
    }

提交回复
热议问题