一尘不染

style =“ clear:both”的用途是什么?

html

我碰巧看到一个div有风格的clear:bothclearin有style什么用?

<div style="clear:both">

阅读 438

收藏
2020-05-10

共1个答案

一尘不染

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    |
|                     |
+---------------------+
2020-05-10