style ="clear:both"有什么用?

tho*_*buj 96 html css

我碰巧看到了div哪种风格clear:both!什么是使用clearstyle

<div style="clear:both">
Run Code Online (Sandbox Code Playgroud)

Ric*_*dle 245

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    |
|                     |
+---------------------+
Run Code Online (Sandbox Code Playgroud)

  • @YevgeniyAfanasyev,是的,这是真的.我的评论是从2009年开始的,当时仍然适用. (5认同)
  • 请小心浮动!http://www.positioniseverything.net/explorer/floatIndent.html (2认同)
  • 它也使父div适合高度. (2认同)

Pau*_*xon 20

只需添加到RichieHindle的回答,请Floatutorial,其中详细介绍了如何CSS浮动和结算工程.