我做了這個:不是水平居中,因爲絕對位置
HTML:
<body>
<div id="header" >
</div>
<div id="main" >
</div>
<div id="footer" >
</div>
</body>
CSS:
body
{
margin:0px;
}
#header
{
width:100%;
background-color:black;
height:60px;
}
#main
{
width:300px;
border:1px dotted black;
margin:0 auto;
}
#footer
{
width:100%;
background-color:black;
height:40px;
position:absolute;
bottom:0px;
}
但正如你所看到的,main
DIV沒有高度。
然後我取代了我的CS說:
body
{
margin:0px;
}
#header
{
width:100%;
background-color:black;
height:60px;
}
#main
{
width:300px;
border:1px dotted black;
position:absolute;
margin:0 auto;
bottom:60px;
top:80px;
}
#footer
{
width:100%;
background-color:black;
height:40px;
position:absolute;
bottom:0px;
}
但隨後,水平中心不起作用。
我怎樣才能做到這一設計(div中心,並採取所有的頁面高度之間的標題和頁腳與20像素magin)?
你將不得不使用Javascript中心div。絕對位置從文檔流中移除元素。 – laymanje 2012-08-01 14:53:21
@laymanje如果不想特別使用'position:absolute;'。我只想做這個設計。 (這與stackoverflow和許多其他網站相同)。 – Mageek 2012-08-01 14:57:07