Tips for clearing floating between CSS hierarchy elements

Source: Internet
Author: User
If you let a parent element wrap a floating child element? There are several ways to do this:

1: Let the parent element also float together: tested the method is feasible, and all around, very tight. But if the current child element has more than one parent,

Then each parent element should be set to float, or even write to the <body>, so the method pass.

2. Set overflow hidden property for parent element: also can implement requirements, but this method has many compatibility issues, you can open several browser test after class

3. Add an empty block element to the current parent element, and this new element only does one thing, clearing the floating elements around it

Testing can also achieve the requirements, this method is the simplest and most intuitive, and there is no compatibility problem, but there is a fatal problem,

That is to add a useless element to the current list of child elements, which can be cumbersome when we use JavaScript and PHP to traverse the data in a scripting language.

Because this element is not what we need and must be dealt with separately, is there a solution to the beauty of the two: to ensure compatibility without adding new elements?

There, with the pseudo-elements we've learned before.

4. Add to the parent element: after pseudo-class, after adding an empty element, directly set its properties;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.