假设这个 html 代码:
<div class="wrap">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
...您可以“浮动”它们:http:
//jsfiddle.net/3rwhd/2/
.wrap {
width: 100%;
}
.item {
float: left;
width: 18%;
margin: 0 1%;
}
...或“内联块对齐”它们(如果您不想要外边距):http:
//jsfiddle.net/3rwhd/1/
.wrap {
width: 100%;
text-align: justify;
}
/* this element will force justificaton */
.wrap:after {
content:'';
display: inline-block;
width: 90%;
height: 0;
}
.item {
display: inline-block;
width: 18%;
}
...或“表格>表格单元”它们:http:
//jsfiddle.net/3rwhd/3/
html:
<div class="wrap">
<div class="item"><div></div></div>
<div class="item"><div></div></div>
<div class="item"><div></div></div>
<div class="item"><div></div></div>
<div class="item"><div></div></div>
</div>
CSS:
.wrap {
display: table;
width: 100%;
}
.item {
display: table-cell;
vertical-align: top;
width: 20%;
}
.item > div {
display: block;
margin: 0 1%;
}
/* optional; remove outer margins */
.item:first-child > div {
margin-left: 0;
}
.item:last-child > div {
margin-right: 0;
}