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

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

藏色散人
Release: 2020-07-02 10:50:43
Original
3506 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template