假設這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>
...你可以 「floatize」 他們: http://jsfiddle.net/3rwhd/2/
.wrap {
width: 100%;
}
.item {
float: left;
width: 18%;
margin: 0 1%;
}
...或「inline-block的理由「他們(如果你不想要外邊距): 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;
}
除非它只是在這個例子中,_please_招你的樣式出來到外部樣式表,並使用一些類/ ID – Bojangles
順便說一句,什麼是1%?外部div的寬度或其中一個內部div的寬度? – biziclop