5

我正在尝试旋转已应用“页面卷曲”投影的 div。

页面卷曲阴影效果在我旋转 div 之前工作正常,此时阴影元素通过 div 显示(z-index 问题)?

我还注意到,如果我有一个图像作为 div 内容,我不会遇到这个问题,但我希望它适用于具有文本内容的 div。有什么建议么?

这是代码:

CSS(移除供应商前缀以缩短代码,但所有现代浏览器都出现此问题):

.shadow {border:1px solid #ccc;position:relative;width:300px;height:116px;background-color:#ededed;}

.shadow:before, .shadow:after {            
    bottom:13px;
    content: "";
    position: absolute;
    z-index: -1;
    -moz-transform: rotate(-11deg);
    box-shadow: 0 15px 5px rgba(0, 0, 0, 0.2);
    height: 50px;
    max-width: 50%;
    width: 50%;
    left:3px;
}
.shadow:after {
    -moz-transform: rotate(11deg);
    left: auto;
    right: 2px;
}

.rotate{
    -moz-transform: rotate(4deg);
}

HTML:

    <div class="shadow">this is the first div</div> <!-- this one is ok -->
    <div class="shadow rotate">this is the second div</div> <!-- this has the issue -->
    <div class="shadow rotate"><img src="//www.google.com/logos/2012/Teachers_Day_Alt-2012-hp.jpg" width="300" height="116"></div> <!-- this one is ok -->

这是一个jsfiddle:http: //jsfiddle.net/U8qY3/5/

4

1 回答 1

4

不错的工作!

作为一种解决方法,您可以在旋转的 div 中放置一个 DIV,将背景颜色设置为下方,并设置完整的高度和宽度,如下所示:http: //jsfiddle.net/U8qY3/6/

HTML

<div class="shadow rotate">
    <div class="workaround">this is the second div</div>         
</div>

CSS

.workaround{
    height: 100%;
    width: 100%;
    background-color: #ededed;
}
于 2012-10-26T10:18:00.880 回答