Home > Web Front-end > CSS Tutorial > Detailed explanation of why css parent class clears floats

Detailed explanation of why css parent class clears floats

黄舟
Release: 2017-10-25 10:06:29
Original
2064 people have browsed it

Floating elements are often used in static web page production. For example, if you want block-level elements to not occupy a single line, you often use float settings to achieve this. However, when applying, you will find that after setting the subclass float, the float is not cleared for the parent class, which will cause the following problems:

     1. The floating element will be relative to the parent container or the front The positioned element is floated. The floated element is separated from the document flow, that is, it no longer occupies its original position, and will affect subsequent elements or the parent container.

                                  over over/under. Normally, the parent container will automatically expand in height. However, after the child element is floated, its position will not be retained. The parent container will feel that it does not exist, so it will not expand in height.

Therefore, when writing static web pages, you must pay attention to the problem of clearing floats. A piece of code to clear floats can be easily called:

 .clearFloat:after{
                content:' ';
                display:block;
                height:0;
                visibility:hidden;
}
          .clearFloat{
                zoom:1;
}
Copy after login

The above is the detailed content of Detailed explanation of why css parent class clears floats. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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