I've started to learn html and css and encountered some misunderstanding... Here is some code:
body {
margin: 0px;
}
#red {
background: red;
width: 100px;
height: 100px;
margin-top: 55px;
margin-left: 30px;
}
#green {
background: green;
width: 200px;
height: 200px;
margin-left: 15px;
margin-top: 55px;
}
<div id="red"></div>
<div id="green"></div>
Here is the red and the green blocks. The red's margin-top is 55px. And it's calculated from the top of the screen (I think the parent is <html>
here). But parent for red block is obviously <body>
. So the question is, why does it happen? Why margin is not calculated from the body?