使margin垂直为0,左右为auto;
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>布局</title>
<style type="text/css">
body{
margin:0; padding:0;
}
.top{
height:100px;
background:blue;
}
.main{
width:800px;
height:300px;
background:#ccc;
margin:0 auto;
}
.foot{
width:800px;
height:100px;
background:#900;
margin:0 auto;
}
</style>
</head>
<body>
<div class="top"></div>
<div class="main"></div>
<div class="foot"></div>
</body>
</html>
运行效果如下: