不能中心网站

时间:2015-10-13 02:28:20

标签: html css html5 css3

我如何使身体居中?我正在尝试构建一个960px的网络,但是在测试时它始终坚持左侧(附上截图)。

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>

2 个答案:

答案 0 :(得分:0)

检查

link

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

答案 1 :(得分:0)

在CSS中,将body规则更改为:

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

centered中没有width值。

小提琴:http://output.jsbin.com/ruhonecifo