prevent children from inheriting transformation css3

后端 未结 4 1340
太阳男子
太阳男子 2020-12-05 10:04

I have a div that i\'m tranforming (scale and translate), but inside that div i have another div. Now i would to see that the inner

4条回答
  •  一个人的身影
    2020-12-05 10:27

    First you can make the children of the parent positioned in the 3D-space by set transform-style: preserve-3d; in parent, then you can apply transform-functions in reverse order of parent to children elements that want to keep front.

    .parent {
      transform: rotateX(33deg) rotateY(66deg) rotateZ(99deg);
      /* Notice! You should make the children of the parent positioned in the 3D-space. */
      transform-style: preserve-3d;
    
      position: relative;
      width: 300px;
      height: 300px;
      margin: 50px auto;
      border: 4px solid darkblue;
    }
    
    .child {
      /* Notice! You should apply the opposite order of rotations (transform functions) from the parent element. */
      transform: rotateZ(-99deg) rotateY(-66deg) rotateX(-33deg);
      position: absolute;
      width: 80px;
      height: 80px;
      background: aqua;
    }
    I'am a child want keep front.

    See: css - How to prevent children from inheriting 3d transformation CSS3? - Stack Overflow

提交回复
热议问题