The content of this article is to share with you a detailed introduction (with code) about one of the best ways to clear floats in CSS. It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. Helps.
When we write web pages, we often worry about the impact of floating. Because the floating child elements cause the parent element to be low, the web page is messed up and cannot achieve the results we want.
Clear floats, I only recommend this method!
The following method has been used since I learned front-end, and I have never changed it, because it is so easy to use:
.clearfix:after{ content: ""; height:0; line-height: 0; display:block; visibility: hidden; clear:both;}
Specific usage:
<ul class="clearfix"> <li style="float:left;"></li> <li style="float:left;"></li> <li style="float:left;"></li> <li style="float:left;"></li></ul>
Sub-element If it floats, just add this class to the parent element. It will work no matter how hard you try it!
Because this style is often used, it is recommended to add it to the public style!
Related recommendations:
Combining html and css to implement the code for mobile web page adaptation
html for access services End method analysis (pictures and text)
The above is the detailed content of A detailed introduction to one of the most useful methods of clearing floats in CSS (with code). For more information, please follow other related articles on the PHP Chinese website!