2012-05-22 92 views
0

使用此代碼塊來創建覆蓋和框。覆蓋和框不透明衝突

問題:該框正在繼承父項的不透明度,我希望它不具有透明度。

#overlay { 
     position: fixed; 
     top: 0; 
     left: 0; 
     width: 100%; 
     height: 100%; 
     background-color: #000; 
     filter:alpha(opacity=50); 
     -moz-opacity:0.5; 
     -khtml-opacity: 0.5; 
     opacity: 0.5; 
     z-index: 10000; 
     text-align: center;   
    } 

    #formed{ 
     background-color: white;  
     width:300px; 
     height:200px; 
     position:relative; 
     left:50%; 
     top:50%; 
     margin:-100px 0 0 -150px; 
    } 

<div id="overlay"><div id="formed">Enter Here</div></div> 

回答

0

謝謝你們。我能夠通過做兩件事來解決問題:

  • 把孩子div帶到父母之外。 <div id="overlay"></div><div id="formed">Here</div>

  • 改變的定位都div的

    #overlay{ 
         position: fixed; 
         top: 0; 
         left: 0; 
         width: 100%; 
         height: 100%; 
         background-color: #000; 
         filter:alpha(opacity=50); 
         -moz-opacity:0.5; 
         -khtml-opacity: 0.5; 
         opacity: 0.5; 
         z-index: 10000; 
         text-align: center; 
         display: none; 
        } 
    
        #formed{ 
         /* for IE */ 
         filter:alpha(opacity=100); 
         /* CSS3 standard */ 
         opacity:1; 
         -webkit-border-radius: 10px; 
         -moz-border-radius: 10px; 
         border-radius: 10px; 
         background-color: white; 
         width:300px; 
         height:200px; 
         position: absolute; 
         left:50%; 
         top:50%; 
         margin:-100px 0 0 -150px; 
         z-index: 12000; 
         border: 2px solid #eee; 
         display: none; 
        } 
    
0

這樣的事情(假設你不需要支持IE7或更早),不透明度適用於僞元素作爲this fiddle does。代碼:

CSS

#overlay { 
     position: fixed; 
     top: 0; 
     left: 0; 
     width: 100%; 
     height: 100%; 
     z-index: 10000; 
     text-align: center;   
    } 

#overlay:after { 
    content: ''; 
    position: absolute; 
    top: 0; 
    right: 0; 
    bottom: 0; 
    left: 0; 
    background-color: #000; 
    filter:alpha(opacity=50); 
    -moz-opacity:0.5; 
    -khtml-opacity: 0.5; 
    opacity: 0.5; 
    z-index: 0; 
} 

#formed{ 
    background-color: white;  
    width:300px; 
    height:200px; 
    position:relative; 
    left:50%; 
    top:50%; 
    margin:-100px 0 0 -150px; 
    z-index: 1; 
}