2011-01-27 158 views

回答

2

固定位置將元素引用到瀏覽器中,而不是父元素。看到此摘錄關於位置是:固定 -

生成絕對定位 元件,位於相對於 瀏覽器窗口。元素的位置 與「左」,「頂」, 「右」,並指定「底」性質

here

你可能想使用position: relative,但沒有源很難肯定知道。

1

將類別centee添加到要居中的對象。將其包裝在類中心的容器周圍。該容器將不可見。

HTML

<div class="centerer"> 
<div class="centee"></div> 
</div> 

CSS

.centerer { 
position: fixed; 
left: 50%; 
height: 50%; 
width: 1px; 
height: 1px; 
} 

.centee { 
    position: absolute; 
    width: 555px; 
    height: 333px; 
    margin-left: -50%; 
    margin-top: -50%; 
    background: blue; 
}