元素的邊框在 Firefox 下莫名消失,問題往往出在浮動沒有被清除。本文示範如何用一行 clear 搞定它。
<div id="box_left"></div>
<div id="box_right"></div>
<div id="box_bottom"></div>
在這個結構裡,box_left 與 box_right 分別向左、向右浮動,而 box_bottom 設有 border。在 IE 下一切正常,但 Firefox 卻不顯示 box_bottom 的邊框。
只要在 box_bottom 的樣式中加上 clear:both;,清除上方浮動的影響,邊框便會乖乖出現。