I recently reviewed some CSS-related knowledge points and sorted out and summarized the classic margin overlap problems in CSS. The purpose is to test the review effect and hope to be helpful to others. If there are any omissions, I would like to ask the front-end veterans to give me advice. Question: When using CSS layout, you will find that the upper and lower margins set by sibling or parent-child nodes will overlap, as shown in the following figure <style> .out { width: 100%; background-color: pink; } .out>div { height: 100px; width: 100%; background-color: rgb(223, 136, 23); margin: 5px 0 10px; } </style> <section class="out"> <div>11</div> <div>22</div> <div>33</div> </section> When we check the height of the entire section, it should actually be 345px, but due to the overlap of the parent and child and sibling margins, we find that the height is 320px. So how to solve this problem in practical applications? The elements inside the BFC do not affect the external elements, and it is a relatively independent closed area; <style> .out { width: 100%; background-color: pink; overflow: hidden; } .out>div { height: 100px; width: 100%; background-color: rgb(223, 136, 23); margin: 5px 0 10px; /* overflow: hidden; */ float: left; } </style> <section class="out"> <div>11</div> <div>22</div> <div>33</div> </section> When we check the height of the section again, we find that the height has returned to 345px, which also proves that when the BFC calculates the height, the height of the floating child elements is also taken into account; This is the end of this article about detailed explanation of CSS margin overlap and solution exploration. For more relevant CSS margin overlap content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Are the value ranges of int(3) and int(10) the same in mysql
>>: A guide to writing flexible, stable, high-quality HTML and CSS code standards
remember: IDE disk: the first disk is hda, the se...
Table of contents Table definition auto-increment...
How to define complex components (class component...
Table of contents Preface 1. Project Architecture...
This article shares the specific code of JavaScri...
Recently, we received a request for help from a c...
This article shares the installation tutorial of ...
Alibaba Cloud Server cannot connect to FTP FileZi...
There are many seemingly true "rumors" ...
This example takes the installation of Python 3.8...
This article introduces the characteristics of CS...
How to convert a JSON string into a JSON object? ...
The players we see on the web pages are nothing m...
To obtain the calculated style in a CSS element (t...
In a table, you can define the color of the lower...