The result you are getting is expected due to the CSS Box Model.
The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.
Explanation of the different parts of the Box Model:
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is transparent
Border - A border that goes around the padding and content
Margin - Clears an area outside the border. The margin is transparent
See the difference between margin and padding illustrated in this snippet:
.container {
background: red;
height: 500px;
}
.inner {
height: 50px;
background: yellow;
}
.margin {
margin-top: 100px;
}
.padding {
padding-top: 100px;
}
<div class="container">
<div class="inner margin">
Inner div has a margin-top
</div>
</div>
<hr>
<div class="container">
<div class="inner padding">
Inner div has a padding-top
</div>
</div>
<hr>
<div class="container">
<div class="inner">
Inner div has no padding/margin
</div>
</div>