Here is my HTML:
<div class='mainDiv'>
<div class='subDiv'></div>
</div>
This is the corresponding CSS code:
.mainDiv {
margin-top: 200px;
width: 700px;
height: 800px;
background-color: red;
}
.subDiv {
background-color: green;
width: 50px;
height: 50px;
margin-top: 22px;
}
View the fiddle here:
Why is the subDiv not receiving the margin-top of 22px? Currently, it only gets a margin top if the pixels are greater than the 200px given to the mainDiv. Is there a way to ensure that the subDiv receives a parent div of 22px relative to the mainDiv without resorting to some kind of hack like adding padding to the parent div?