我有三列,但在中心一個我只能顯示有限數量的段落。 例如,如果我添加15個段落,則只會顯示前11個段落。這就像div有設置高度參數。有誰知道如何解決這一問題?中心div有高度限制
<div id="left" style="float:left; width:250px;"></div>
<div id="right" style="float:right; width:250px;"></div>
<div id="center" style="margin:0;"></div>
我有三列,但在中心一個我只能顯示有限數量的段落。 例如,如果我添加15個段落,則只會顯示前11個段落。這就像div有設置高度參數。有誰知道如何解決這一問題?中心div有高度限制
<div id="left" style="float:left; width:250px;"></div>
<div id="right" style="float:right; width:250px;"></div>
<div id="center" style="margin:0;"></div>
也加入float:left;
您#center
元素
,或者如果你不希望它比浮動:overflow:auto;
另一種方法是使用display: table;
和display: table-cell;
代替:
CSS
#container {
display: table;
width: 100%;
}
.cell {
display: table-cell;
vertical-align: top;
}
.side {
width: 250px;
}
HTML
<div id="container">
<div class="cell side">Left</div>
<div class="cell">Center</div>
<div class="cell side">Right</div>
</div>
我假設這些都爲你的佈局積木,對左,右一箇中心區和側欄。使用table
具有所有單元保持相同高度的益處; float
可以變幻莫測。
要小心,如果你添加float:left,那麼你還需要一個設置寬度(假設一個固定寬度的佈局,否則這種方法是沒有用的),因爲float會隨着內容拉伸並且不適合在間隙內。只要你不需要可見的溢出,溢出方法就可以。 –