2015-10-13 23 views
0

我如何居中?我正在嘗試構建一個960像素的網頁,但是當測試時它始終保持在左側(附上截圖)。不能居中網站

enter image description here

我該如何解決這個問題?感謝所有能夠幫助的人!

<html> 
<head> 
<style> 

body { 
background-color:WHITE; 
width: 960px centered; 
} 

.one { 
background: #B1B4B5; 
color: BLACK; 
font-size: 60px; 
width: 60px; 
height: 60px; 
overflow:hidden; 
float:left; 
position:absolute; 
top: 0px; 
left: 0px; 
text-align: center; 
} 

.two { 
background: #B1B4B5; 
color: BLACK; 
font-size: 60px; 
width: 60px; 
height: 60px; 
overflow:hidden; 
float:left; 
position:absolute; 
top: 0px; 
left: 900px; 
text-align: center; 
} 

.three{ 
background: #B1B4B5; 
color: BLACK; 
font-size: 60px; 
width: 60px; 
height: 60px; 
overflow:hidden; 
float:left; 
position:absolute; 
top: 500px; 
left: 0px; 
text-align: center; 
} 

.four { 
background: #B1B4B5; 
color: BLACK; 
font-size: 60px; 
width: 60px; 
height: 60px; 
overflow:hidden; 
float:left; 
position:absolute; 
top: 500px; 
left: 900px; 
text-align: center; 
} 

</style> 
</head> 
<body> 

<a class="one">1</a> 
<a class="two">2</a> 
<a class="three">3</a> 
<a class="four">4</a> 

</body> 
</html> 
+1

到中心通常應用餘量餘量{:0汽車;} – Praveen

+0

設定寬度和餘量:0汽車;將任何屏幕的容器居中 – Saran

回答

0

在CSS中,body規則更改爲:

body { 
    background-color: white; 
    width: 960px; 
    margin: auto; 
    position: relative; 
} 

有在width沒有centered值。

小提琴:在元件 體0汽車:http://output.jsbin.com/ruhonecifo

0

入住這

link

body 
{ 
    background-color: WHITE; 
    //incorrect value (width: 960px centered;) 
    width: 960px; 
    margin: 0 auto; 
    position: relative; 
}