Why does adding a div to the shell look different with respect to the inner div?

I have 2 divs

<div id=number1><div id=number2></div></div> 

Why

 #number1 { background:red; } #number2 { background:blue; height: 200px; margin: 10px; } 

Not the same as

 #number1 { background:red; padding:10px; } #number2 { background:blue; height: 200px; } 

And in the first case, I get white lines above and below, where it is assumed that this is the red color of div 1? http://jsfiddle.net/ZbCNq/

+3
source share
2 answers

In the first case, the unexpected behavior that you experience is associated with "folding fields."

Specification:

A bit easier to read:

You can fix this:

+3
source

This is because Fill is used to Block to Content. and โ€œMarginโ€ is used to โ€œBlockโ€ to โ€œBlockโ€ the distance.

+1
source

Source: https://habr.com/ru/post/1389433/


All Articles