2011-01-27 97 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; 
}