我不想把所有DIV套在一个大的DIV里,如何使这些DIV在整个版面里居中
山水无言 2011-02-06 10:17:28 下面代码是根据网上的代码简单修改之后的结果,从显示效果看,第一行显示4个DIV,第二行显示2个DIV,它们在整个版面里不会居中,左边更宽,右边更窄。我有设置margin: 0px auto;按理说应该会居中呀,怎么回事,怎么修改?
前提是:我不想把所有DIV套在一个大的DIV里,如何使这些DIV在整个版面里居中。
我从网上看到,把所有DIV套在一个大的DIV里,不是很好的设计方法,而且会影响网页下载速度。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>盒子模型</title>
<style type="text/css">
body,html{
font-size: 12px;
margin: 0px auto;
height: auto;
width: 900px;
}
.mainBox{
border: 1px dashed #0099CC;
margin: 2px;
padding: 0px;
float: left;
height: 300px;
width: 192px;
}
.mainBox span{
float: left;
height: 16px;
width: 179px;
color: #FFFFFF;
padding: 6px 3px 3px 10px;
background-color: #0099CC;
font-size: 12px;
}
.mainBox p{
line-height: 1.5em;
text-indent: 2em;
margin: 35px 5px 5px 5px;
}
</style>
</head>
<body>
<div class="mainBox">
<span>前言</span>
<p>正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容</p>
</div>
<div class="mainBox">
<span>CSS盒子模式</span>
<p>正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容</p>
</div>
<div class="mainBox">
<span>转变思想</span>
<p>正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容</p>
</div>
<div class="mainBox">
<span>熟悉步骤</span>
<p>正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容</p>
</div>
<div class="mainBox">
<span>增加1</span>
<p>正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容</p>
</div>
<div class="mainBox">
<span>增加2</span>
<p>正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容</p>
</div>
</body>
</html>