2009-06-18 77 views

回答

227

clear:both使元素落在文檔中的任何浮動元素之前。

您還可以使用clear:leftclear:right使其僅落在已向左或向右浮動的元素的下方。

+------------+ +--------------------+ 
|   | |     | 
| float:left | | without clear | 
|   | |     | 
|   | +--------------------+ 
|   | +--------------------+ 
|   | |     | 
|   | | with clear:right | 
|   | | (no effect here, | 
|   | | as there is no | 
|   | | float:right  | 
|   | | element)   | 
|   | |     | 
|   | +--------------------+ 
|   | 
+------------+ 
+---------------------+ 
|      | 
| with clear:left | 
| or clear:both | 
|      | 
+---------------------+ 
+33

+1原理圖答案。很好的解釋 – 2009-06-18 11:34:08

+2

注意FLOAT BUG! http://www.positioniseverything.net/explorer/floatIndent.html – Jason 2009-07-22 23:19:34

20

只需添加到RichieHindle的回答,請Floatutorial,其中詳細介紹瞭如何CSS浮動和結算工程。

2

當您使用float不帶寬度時,該行中仍有一些空格。要阻止此空間,您可以在下一個元素中使用clear:both;

相關問題