Home > Web Front-end > CSS Tutorial > Super simple way to close floating elements_CSS/HTML

Super simple way to close floating elements_CSS/HTML

WBOY
Release: 2016-05-16 12:12:14
Original
1456 people have browsed it

A very good little tip I saw accidentally. It’s about using CSS to handle closed floating elements. I collected it.

There are many methods for closing floating elements (clearing float). You still haven’t. If you know more about it, check out old9’s blog. There is an article about closing floating elements.

My favorite of these methods is to use the :after pseudo-class to dynamically embed an element for clearing floating elements. Unfortunately, the amount of code is too large and it doesn’t look concise enough. Now I see there is a super simple method. Let me introduce it quickly. The original text is at: http://annevankesteren.nl/2005/03/clearing-floats

The principle is this. The reason why peripheral elements cannot be extended well is the overflow. on, because the overflow is not visible. See W3C’s explanation

Quotation content:
In addition, if the element has any floating descendants whose bottom margin edge is below the bottom, then the height is increased to include those edges. Only floats that are children of the element itself or of descendants in the normal flow are taken into account, e.g., floats inside absolutely positioned descendants or other floats are not.

Now just add an overflow:auto; to the peripheral element to solve the problem. The result is that except for IE, it can really be solved. The problem of IE will be solved next. Add _height:1%; and the problem will be completely solved.

The following are three examples I made for comparison

1.No closed floating element
2.Closed floating element under non-IE
3.Completely closed element

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template