2011-01-24 118 views
0

这里是页:http://aevm.ca/fond2.html水平居中

当我使用这个CSS: 它的左对齐和顶在零

#center { 
    height: 100%; 
    width: 960px; 
    position: absolute; 
    background-color: #FF0; 
    top: 0px; 
    margin-right: auto; 
    margin-left: auto; 
    } 

当我使用这个CSS: 它的中心对齐和顶部10 -20像素(为什么?)

#center { 
     height: 100%; 
     width: 960px; 
     position: relative; (the only difference) 
     background-color: #FF0; 
     top: 0px; 
     margin-right: auto; 
     margin-left: auto; 
     } 

我怎么能得到顶级位置和水平中心?

回答

2

#center上使用position: relative

这是您的源代码第16行:

<script src="jquery.backstretch.min.js" .. ></script><br> 

摆脱偷偷摸摸<br>:d

+1

a-ma-zig catch!...做到了! – menardmam 2011-01-24 22:44:51

0

如果职位是relative您必须输入margin-top:0;试试这个;

#center { 
     height: 100%; 
     width: 960px; 
     position: relative; (the only difference) 
     background-color: #FF0; 
     margin: 0 auto; 
     } 
+0

没了!这不做任何事情! – menardmam 2011-01-24 22:42:54