In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what is the method of removing floats in css. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Consequences of floating:
(1) because the floating element is separated from the document flow, the height of the parent element cannot be stretched, affecting the elements at the same level as the parent element.
(2) non-floating elements at the same level as floating elements follow, because floating elements leave the document stream and do not occupy their original position.
(3) if the floating element is not the first floating element, the element before the element also needs to float, otherwise it will easily affect the structure of the page.
Example: set three div in a div and let three div support the parent element
.box {border:1pxsolid#ccc;background:pink;}
.red {width:100px;height:100px;background:red;}
.green {width:100px;height:100px;background:green;}
.blue {width:100px;height:100px;background:blue;}
Effect picture:
After adding float:left, the parent element cannot be supported.
Clear the method of floating
(1) use clear:both to clear floats
Put an empty div tag in the code, and then set clear:both to the tag to clear the impact of the float on the page. It has the advantages of simplicity, convenience and good compatibility, but in general, this method is not recommended because it will cause structural confusion and is not conducive to later maintenance.
(2) use pseudo element clearfix to clear floats
An after pseudo element is added to the parent element, which can prop up the height of the parent element by removing the float of the pseudo element.
.clearfix: after {
Content: ""
Display:block
Visibility:hidden
Clear:both
}
(3) the use of overflow method
When the overflow style is set for the parent element, either overflow:hidden or overflow:auto can clear the float as long as its value is not visible. Its essence is to construct a BFC, which makes it possible to prop up the height of the parent element.
.box {border:1pxsolid#ccc;background:#eff2f4;overflow:auto}
(4) the use of double pseudo element method.
The effect of clearing the float is achieved by setting double pseudo elements to the parent element.
.clearfix: before,.clearfix:after {
Content: ""
Display:block
Clear:both
}
This is the end of this article on "what is the way to remove floats in css". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.