2012-08-15 24 views
0

我試圖做一個彈出框,導致周圍地區變灰。我的問題是影子div的不透明度似乎超過了彈出窗口的不透明度。我嘗試改變從絕對位置到固定位置,增加彈出窗口的z索引,但都不起作用。絕對定位元素的不透明度

Here是該問題的屏幕畫面。

而且下面是培訓相關的代碼(詢問你是否需要查看更多)

.textPopup 
{ 
    width: 1400px; 
    height: 600px; 
    background-color: White; 
    position: fixed; 
    margin-left: auto; 
    margin-right: auto; 
    z-index: 15; 
    left: 0; 
    right: 0; 
    top: 50px; 
    bottom: 0; 
    opacity: 0.2; 
} 
#innerPopup 
{ 
    background-color: White; 
    width: 1350px; 
    height: 550px; 
    position: absolute; 
    margin-left: auto; 
    margin-right: auto; 
    z-index: 15; 
    left: 0; 
    right: 0; 
    top: 50px; 
    bottom: 0; 
    opacity: 1; 
} 

... snip 
    <div id="popupShadow"> 
    </div> 
    <div class="textPopup"> 
     <div id="innerPopup"> 
     </div> 
    </div> 
</body> 
</html> 
+2

您的屏幕截圖鏈接返回404未找到。 – 2012-08-15 09:53:59

+0

我重新上傳它。只需一秒 – 2012-08-15 09:56:09

回答

3

您遇到的問題是#innerPopup#textPopup之內。然後不透明度由孩子繼承,不能被它自己的屬性覆蓋。

如果它是不可能將它們分開,然後再考慮使用背景的rgba值相對於opacity屬性:

#textPopup { 
    background-color: rgba(255,255,255,0.2); 
} 

你可以看到它在jsfiddle工作。

0

您將能夠使它工作通過在你的CSS以下變化預期:

#innerPopup 
{ 
    position: relative; /* change this to relative - will allow you to override the parent specified opacity */ 

    opacity: 1; 

    /* other properties */ 
} 
+0

#innerpopup也需要更高的z-index而不是.textPopup。 – 2012-08-15 10:05:01

+0

「位置」是「相對」還是「絕對」並不重要,該元素仍然是孩子,並且會繼承父級的不透明度。嘗試在jsfiddle中:http://jsfiddle.net/cchana/fC2Mz/ – cchana 2012-08-15 10:11:33