Style = “ clear: both”有什么用?

我碰巧看到一个 div的风格是 clear:both! clearstyle中有什么用?

<div style="clear:both">
113308 次浏览

clear:both makes the element drop below any floated elements that precede it in the document.

You can also use clear:left or clear:right to make it drop below only those elements that have been floated left or right.

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

Just to add to RichieHindle's answer, check out Floatutorial, which walks you through how CSS floating and clearing works.

When you use float without width, there remains some space in that row. To block this space you can use clear:both; in next element.