2014-04-22 19 views
0

我嘗試把一個div 100%的頁面內容的頂部。問題出現在內容有一定餘量時。我在這裏用一個簡化的例子來說明。頂部100%

如果我明白,位置固定:「該元素相對於瀏覽器窗口定位」。那麼,爲什麼div .trans會受到背後的影響?如何把div透明100%的頁面和內容的頂部?

這裏就是看這個問題,並嘗試解決方案的好地方:http://jsfiddle.net/rdkAW/1/

CSS:

body { margin:0; } 

.trans{ 
    position:fixed; 
    width:100%; height:100%; 
    margin:0; 
    opacity:0.7; filter: alpha(opacity = 70); 
    background-color:red; 
    z-index:5; 
} 

#content { 
    position:relative; 
    margin:30px auto; /* is this the problem? */ 
    width:95%; max-width:890px; height:1200px; 
    z-index:1; 
    background-color:blue; 
} 

HTML:

<div class="trans"></div> 
<div id="content"></div> 

回答

0

如果我使用的問題就解決了。頂部:0;左:0;看起來這個位置固定需要。我仍然不明白爲什麼。如果固定div是100%,並且根據定義固定位置是相對於窗口,爲什麼需要指定頂部和左側?如果有人能解釋它,我將不勝感激。