prevent children from inheriting transformation css3

后端 未结 4 1314
太阳男子
太阳男子 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:12

    .parent {
        position: relative;
        background-color: yellow;
        width: 200px;
        height: 150px;
        margin: 70px;
        -webkit-transform: rotate(30deg);
        -moz-transform: rotate(30deg);
        -o-transform: rotate(30deg);
        -ms-transform: rotate(30deg);
        transform: rotate(30deg);
    }
    
    .child {
        position: absolute;
        top: 30px;
        left: 50px;
        background-color: green;
        width: 70px;
        height: 50px;
        -webkit-transform: rotate(-30deg);
        -moz-transform: rotate(-30deg);
        -o-transform: rotate(-30deg);
        -ms-transform: rotate(-30deg);
        transform: rotate(-30deg);
    }
    <div class="parent">
        <div class="child"></div>
    </div>

    0 讨论(0)
  • 2020-12-05 10:13

    Here is it what worked for me..

    I used opposite transition for children. Then it was stable

    .logo {
        background: url('../images/logo-background.png') no-repeat;
        width: 126px;
        height: 127px;
        margin-top:-24px;
        z-index: 10;
        display: block;
    
    }
    a.logo span{
        display: block;
        width: 126px;
        height: 127px;
        background: url('../images/logo-bismi.png') no-repeat;
        z-index: 20;
        text-indent: -9999px;
        text-transform: capitalize;
        -webkit-transition: -webkit-transform 0.4s ease-out;
        -moz-transition: -moz-transform 0.4s ease-out;
        transition: transform 0.4s ease-out;    
    
    }
    a.logo:hover span{
        -webkit-transform: rotateZ(-360deg);
        -moz-transform: rotateZ(-360deg);
        transform: rotateZ(-360deg);
    }
    a.logo {
        -webkit-transition: -webkit-transform 0.4s ease-out;
        -moz-transition: -moz-transform 0.4s ease-out;
        transition: transform 0.4s ease-out;        
    }
    a.logo:hover{
        -webkit-transform: rotateZ(360deg);
        -moz-transform: rotateZ(360deg);
        transform: rotateZ(360deg); 
    }
    
    0 讨论(0)
  • 2020-12-05 10:22

    Do as usual. Set "transform: none" to all of children.

    .children1,
    .children2,
    .childrenN {
        -moz-transform: none;
        -webkit-transform: none;
        -o-transform: none;
        -ms-transform: none;
        transform: none;
    }
    
    0 讨论(0)
  • 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;
    }
    <div class="parent">
      <div class="child">
        I'am a child want keep front.
      </div>
    </div>

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

    0 讨论(0)
提交回复
热议问题