Home  >  Article  >  Web Front-end  >  Summary of methods to clear floating floats

Summary of methods to clear floating floats

高洛峰
高洛峰Original
2017-03-16 10:34:521607browse

Abandon those useless methods and just remember the most practical method!

Add an additional class attribute to the parent element that needs to clear floating: clearfix! ! !

The style is as follows:

.clearfix:after{
content:".";
display:block; # Current projects have almost completely ignored it)
.clearfix{
zoom:1
}

Clearing floats is so simple and can be used as a public style common.css, every page can be called directly!

Simple example application:

 

   //sth

 

 

Why do we need to clear floats:

1 .When I was writing before, I would find that the pages were messed up as I wrote them, and there were also overlaps? It’s the floating that’s to blame!

2. When the child element under the parent element floats, the parent height value may be 0; therefore, after using float, immediately add clearfix to the parent to completely eliminate the problems caused by float. All kinds of weird questions!

The above is the detailed content of Summary of methods to clear floating floats. 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