2012-10-26 42 views
5

我試圖旋轉一個div,我已經應用了'頁面捲曲'陰影。css頁面捲曲效果陰影與旋轉

頁面捲曲陰影效果工作正常,直到我旋轉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

不錯的工作!

作爲一種變通方法,你可以把一個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; 
} 
+1

就是這樣!你們很快*。它也適用於其他現代瀏覽器。 – caitriona

+1

ps。我可以沒有信譽的巧妙陰影效果。我發現它'在互聯網上'。 – caitriona

+1

這是一個很好的效果。你們倆都做得很好:) – Harry