css - 父子 div 的 3d 变换

标签 css css-transforms

为什么要使用以下 HTML:

<div class="container">
    <div class="bottom">
        <div class="face"></div>
    </div>
</div>

和 CSS:

.container {
    width: 300px;
    height: 300px;
    position: relative;
    transform: perspective(900px);
    transform-style: preserve-3d;
    animation: rot 8s infinite linear;
}
.bottom {
    width: 200px;
    height: 200px;
    background-color: blue;
    position: absolute;
    top: 15%;
    left: 15%;
    opacity: 1;
}
.face {
    width: 100px;
    height: 200px;
    background-color: red;
    position: absolute;
    left: 0px;
    top: 0px;
    transform-origin: 0% 0%;
    transform: rotateY(60deg);
}

蓝色方 block 在返回时没有覆盖红色矩形(backface-visibility 没有帮助)?同时,当 .bottom.face 不在父子关系中时,一切都按预期进行。

参见 plunker

注意:适用于 Chrome。在 Firefox 中,第一个示例不起作用。在 IE 中。

最佳答案

大多数 CSS 属性都是继承的。

transform-style 是个异常(exception)

设置

.bottom {
    transform-style: preserve-3d;
}

.bottom {
    transform-style: inherit;
}

会解决问题

demo

关于css - 父子 div 的 3d 变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31123779/

相关文章:

html - 位置粘性不生效

CSS 设置绝对位置

html - 如何使移动网站中的边距和边框不可见 html/css

html - 悬停时有 3 个链接动画,但 1 个链接没有

css - 元素旋转和transform-style导致显示不一致 : preserve-3d

html - 指针事件结合悬停 css

html - 如何在不影响响应设备的情况下在 div 的底部进行倾斜

css - Safari 不会将图像拉伸(stretch)到 flexbox 网格

CSS 字体在 Opera 中看起来很奇怪

javascript - 是否可以像这样用 CSS 剪切 DIV 的一侧?