Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways for HTML to clear floats?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report