你能看看这段代码,让我知道我如何能把一个div分成3列和2行,像下面的图像?
|--------|--------|---------|
| | | |
| 1 | 2 | 3 |
| | | |
|---------------------------|
| | | |
| 4 | 5 | 6 |
| | | |
|--------|--------|---------|
我已经在这个演示中试过了,但是没有成功!
<div id="main">
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
<div id="5"></div>
<div id="6"></div>
</div>
#main{width:300px; height:150px; border:1px solid #ccc;}
#1{width:50px; height:75px; border:1px solid #ccc;}
#2{width:50px; height:75px; border:1px solid #ccc;}
#3{width:50px; height:75px; border:1px solid #ccc;}
#4{width:50px; height:75px; border:1px solid #ccc;}
#5{width:50px; height:75px; border:1px solid #ccc;}
#6{width:50px; height:75px; border:1px solid #ccc;}
HTML:
<div id="main">
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
<div id="5"></div>
<div id="6"></div>
</div>
CSS:
#main {
width: 350px;
height:200px;
}
#main div {
width: 100px;
height: 50%;
border: 1px solid #ccc;
float: left;
}
#main
的宽度在px中应该大于#main div
宽度的3倍ie #main_width > 3* div_width
高度应该为主div指定,并且可以为各个div定义百分比。
如果您使用div
标记作为单元格,您可能需要查看table
显示属性: