防止孩子继承转换css3

时间:2011-08-12 19:08:49

标签: css css3

我有div我正在进行转换(缩放和翻译),但在div内我有另一个div。现在,我会看到内部div不受其父级转换的影响,换句话说。我希望内部div不像父母那样扩展。

这是html:

<div id="rightsection">
    <div class="top"></div>
    <div class="middle">
          <div class="large">
            <img src="assets/images/rightpanel_expanded.png" alt="map" title="map"/>
          </div>
    </div>
    <div class="bottom">
        <p>Check if your friends are going!</p>
    </div>
</div>

这是我的css:

#rightsection:hover {
    -moz-transform:scale(2.16,2.8) translate(-80px,-53px);
    -webkit-transform:scale(2.16,2.8) translate(-80px,-53px);
    -o-transform:scale(2.16,2.8) translate(-80px,-53px);
    -ms-transform:scale(2.16,2.8) translate(-80px,-53px);
    transform:scale(2.16,2.8) translate(-80px,-53px)
}

问题是,当我缩放#rightsection时,img会缩放到,但我希望将图像保持原始大小。

感谢任何帮助。

4 个答案:

答案 0 :(得分:2)

像往常一样。为所有孩子设置“transform:none”。

.children1,
.children2,
.childrenN {
    -moz-transform: none;
    -webkit-transform: none;
    -o-transform: none;
    -ms-transform: none;
    transform: none;
}

答案 1 :(得分:1)

.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>

答案 2 :(得分:0)

这对我有用..

我为孩子们使用了相反的过渡。然后它很稳定

.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); 
}

答案 3 :(得分:0)

首先,您可以通过在父级中设置transform-style: preserve-3d;来使父级的子级位于3D空间中,然后可以按父级的反向顺序将变换功能应用于子级元素想要保持领先地位的人。

.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>

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