如果您在具有固定寬度的父div中彼此相鄰的多個div並且將子div的寬度設置爲固定父級的百分比,有時子div不能全部在同一行顯示,但子div的寬度百分比總和爲100%。按寬度百分比設置多個div以填充彼此相鄰的父div
HTML:
<div id="parent">
<div class="child" style="width:51.5%;">1</div>
<div class="child" style="width:0.58333333333333%;">2</div>
<div class="child" style="width:21.666666666667%;">3</div>
<div class="child" style="width:0.56944444444444%;">4</div>
<div class="child" style="width:15%;">5</div>
<div class="child" style="width:0.23611111111111%;">6</div>
<div class="child" style="width:6.7361111111111%;">7</div>
<div class="child" style="width:0.69444444444444%;">8</div>
<div class="child" style="width:2.3611111111111%;">9</div>
<div class="child" style="width:0.47222222222222%;">10</div>
<div class="child" style="width:0.18055555555556%;">11</div>
</div>
CSS:
#parent{
float:left;
width:850px;
overflow:hidden;
}
.child{
border:1px solid red;
float:left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color:blue;
white-space: nowrap;
overflow:hidden;
}
http://jsfiddle.net/4gvgqkkc/3/
任何想法?
子像素四捨五入由不同瀏覽器管理。 – 2014-10-27 11:08:28