我想知道是否有可能讓我的包裝div在瀏覽器調整大小時緊緊圍繞浮動子div(.box)。目前,如果瀏覽器被調整大小,第四個div將繼續到下一行,但是wrapper div將保持相同的大小,就像它仍然存在一樣,但是我希望它可以縮小,因此它完全適合左側3個div如果這是有道理的......我將如何實現這一目標?立即圍繞浮動的孩子包裝父div
的jsfiddle - http://jsfiddle.net/JCGj6/
<div class="showcase_wrapper">
<div class="showcase" id="pt1">
<div class="inner">
<div class="box"> One </div>
<div class="box"> Two </div>
<div class="box"> Three </div>
<div class="box"> Four </div>
</div>
</div>
</div>
.inner {
position:relative;
}
.showcase_wrapper {
margin:170px auto 0px auto;
max-width:848px;
position:relative;
}
.showcase {
position:absolute;
top:0;
width:100%;
min-width:424px;
display:inline-block;
white-space:normal;
float:left;
z-index:0;
border:1px solid #ff0000;
background:#ff000;
}
.showcase .box {
position:relative;
background:#ff0000;
width:212px;
height:173px;
float:left;
cursor:pointer;
}
上面似乎未爲Firefox(蘋果OSX)工作。紅色的邊界框仍然延伸到最遠的地方,因爲每個廣場都落在下一行,而不是像OP要求的那樣捕捉它的內容孩子。 – Pebbl
即使我刪除最小寬度也沒有區別: -/ –
IT看起來像是默認行爲。 http://jsfiddle.net/Kyle_Sevenoaks/LRxr4/ OP可能需要使用JS來計算任何給定時刻的寬度並強制它。 – Kyle