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
This article example shares the specific code of ...
This article shares the specific code of vue echa...
I have written many projects that require changin...
1. Implement call step: Set the function as a pro...
Preface Recently, a data was operated incorrectly...
Table of contents Preface Type Inference Truth va...
Table of contents Set a not null constraint when ...
1. Log4j for log segmentation 1) Prepare three pa...
Table of contents 1. How to represent the current...
There are many tags and elements in the HTML head ...
Table of contents 1. Use default parameters inste...
I encountered mysql ERROR 1045 and spent a long t...
This article example shares the specific code of ...
Some tips for deep optimization to improve websit...
How to install and configure MySQL on Mac OS 10.1...