Why does the margin 20 of two consecutive divs not appear 40? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:08:14
Original
1015 people have browsed it

Why are the margins of two consecutive divs set to margin:20px auto;
My understanding should be that there is a 40px gap between the two divs. But it displays only 20px

Why is it so strange?

<style type="text/css">	.div1{margin:20px auto;width:500px;height:100px;background-color:#FF99FF;overflow:hidden;}	.div2{margin:20px auto;width:500px;height:100px;background-color:#339933;overflow:hidden;}	.div3{margin:20px auto;width:500px;height:100px;background-color:#9933FF;overflow:hidden;}</style><div class="div1"></div><div class="div2"></div><div class="div3"></div>
Copy after login


Reply to discussion (solution)

Understand the box model, it is the distance between two borders

This is the margin merging phenomenon in the specification

The margin setting is relative to the div set by itself, and does not involve other divs, so it is not 40px.

External padding is only for your own DIV, it has nothing to do with anyone else!

Vertical margins are merged

Learning Posts

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