CSS z-index paradox flower

后端 未结 6 479
遇见更好的自我
遇见更好的自我 2021-01-29 20:20

I would like to create a paradoxical effect via the z-index CSS property.

In my code I have five circles, like in the image below, and they are all absolute

6条回答
  •  滥情空心
    2021-01-29 20:59

    My attempt also using clip. The idea was to have half and half for the div. That way setting z-index would work.

    So you can set the top part to z-index: -1 and the bottom to z-index: 1.

    Outcome:

    enter image description here

    .item {
      width: 50px;
      height: 50px;
      line-height: 50px;
      border: 1px solid red;
      background: silver;
      border-radius: 50%;
      text-align: center;
    }
    .under {
      z-index: -1;
    }
    .above {
      z-index: 1;
      overflow: hidden;
      clip: rect(30px 50px 60px 0);
    }
    .i1 {
      position: absolute;
      top: 30px;
      left: 0px;
    }
    .i2 {
      position: absolute;
      top: 0px;
      left: 35px;
    }
    .i3 {
      position: absolute;
      top: 30px;
      left: 65px;
    }
    .i4 {
      position: absolute;
      top: 70px;
      left: 50px;
    }
    .i5 {
      position: absolute;
      top: 70px;
      left: 15px;
    }
    1
    1
    2
    3
    4
    5

    DEMO HERE

    Note: Tested on IE 10+, FF 26+,Chrome 33+ and Safari 5.1.7+.

提交回复
热议问题