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

我碰巧看到一个div,它的风格是clear:bothclearstyle中的用途是什么?

<div style="clear:both">
thomasbabuj asked 2019-08-13T17:29:03Z
3个解决方案
241 votes

clear:left使元素下降到文档中位于其前面的任何浮动元素下方。

您还可以使用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    |
|                     |
+---------------------+
RichieHindle answered 2019-08-13T17:29:26Z
20 votes

只需添加RichieHindle的答案,请查看Floatutorial,它将引导您了解CSS浮动和清除的工作原理。

Paul Dixon answered 2019-08-13T17:29:52Z
3 votes

当您使用没有宽度的float时,该行中仍有一些空间。 要阻止此空间,您可以在下一个元素中使用clear:both;

imdad answered 2019-08-13T17:30:18Z
translate from https://stackoverflow.com:/questions/1012131/what-is-the-use-of-style-clearboth