Home  >  Article  >  Web Front-end  >  How to clean up floats when a container contains several floating elements

How to clean up floats when a container contains several floating elements

藏色散人
藏色散人Original
2020-07-02 10:50:433483browse

When a container contains several floating elements, the way to clear the floats is to add additional elements and set "clear: both" before the closing tag of the container element. "clear: both" means clearing the floats.

How to clean up floats when a container contains several floating elements

Add additional elements before the closing tag of the container element and set clear: both

The parent element triggers block-level formatting Context

  • Block-level formatting context, it is an independent rendering area, this area has nothing to do with the outside.

Trigger condition:

  • Root element (for example: html)

  • The element is floated ( float is not none)

  • position is absolute or fixed

  • display is inline-block, table-sell, flex...

  • overflow is not visible

Set container element pseudo-element for cleaning (recommended method of cleaning floats)

Recommended learning: "Front-end video

The above is the detailed content of How to clean up floats when a container contains several floating elements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn