|
關于閉合浮動元素(clearing float)的方法現在已經很多了,你還不了解的話去old9的blog看看,有一篇閉合浮動元素。
這些方法我最喜歡就是 使用:after 偽類動態的嵌入一個用于清除浮動的元素,可惜代碼量太大了,看著不夠簡潔。現在我看到有個方法超級簡單。趕緊介紹一下。原文在:http://annevankesteren.nl/2005/03/clearing-floats
原理是這樣的,外圍元素之所以不能很好的延伸,問題出在了overflow上,因為overflow不可見。見W3C的解釋
引用內容:In addition, if the element has any floating descendants whose bottom margin edge is below the bottom, then the height is increased to include those edges. Only floats that are children of the element itself or of descendants in the normal flow are taken into account, e.g., floats inside absolutely positioned descendants or other floats are not.
現在只要將給外圍元素添加一個overflow:auto;就可以解決問題,結果是除了IE,真的可以解決。下來就要解決ie的問題了,再加上_height:1%; ,這個問題就完全解決了。
下面是我做的三個例子作為比較
1.沒有閉合浮動元素
2.非IE下閉合浮動元素
3.完全閉合元素
[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]
HTML/CSS技術:閉合浮動元素超級簡單的方法,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。