Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways for HTML to clear floats?

Shulou Source: shulou.com Published: 2022-06-01 03:45:32 11月15日 Update

This article introduces the relevant knowledge of "what are the methods of clearing floats in HTML". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Method 1. Add an empty div tag clear:both at the end

Place a tag under the floating box and use clear:both in this tag to remove the impact of the float on the page.

Note: this method is not normally used to clear floats. Because this way to clear the float will increase the tag of the page, resulting in structural confusion.

one

two

three

Method 2. Parent div defines overflow: auto

Principle: one thing to note about using the overflow attribute to clear floats is that the overflow attribute has three property values: hidden,auto,visible. We can use hiddent and autovalues to clear floats, but remember not to use visible values

one

two

three

Method 3. Use pseudo elements to clear floats (: after, note: acting on the parent of floating elements)

(note: this method is mainly recommended)

.clearfix: after {

Content: ""; / * set the content to empty * /

Clear:both;/* clear float * /

Display:block;/* converts text to block-level elements * /

The height of height:0;/* is 0 feet /

Visibility:hidden;/* hides elements * /

}

.clearfix {

Zoom:1;/* for compatibility with IE*/

}

This is the end of the content of "what are the ways for HTML to clear floats". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Floating method element tag content attribute situation way more knowledge page utility confusion achievement next three function principle dilemma practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Apple Shulou Tech Info Redmi MySQL