The floated box (pink one) should have been zero margin on the top, but it seems to be the same margin-top as the green one. Why?
* {
padding: 0;
margin: 0;
}
.normalBox {
width: 50px;
height: 50px;
background-color: pink;
}
.largerBox {
width: 100px;
height: 100px;
background-color: green;
}
.margin-10px {
margin: 10px
}
.float {
float: left;
}
<div class="normalBox float"></div>
<div class="largerBox margin-10px"></div>
But this problem disappeared when the green one also has zero margin:
* {
padding: 0;
margin: 0;
}
.normalBox {
width: 50px;
height: 50px;
background-color: pink;
}
.largerBox {
width: 100px;
height: 100px;
background-color: green;
}
.margin-10px {
margin: 10px
}
.float {
float: left;
}
<div class="normalBox float"></div>
<div class="largerBox"></div>
Or there is a previous sibling box that also has no margin, the pink one and the green one just acts as expected:
* {
padding: 0;
margin: 0;
}
.normalBox {
width: 50px;
height: 50px;
background-color: pink;
}
.normalBox2 {
width: 50px;
height: 50px;
background-color: orange;
}
.largerBox {
width: 100px;
height: 100px;
background-color: green;
}
.margin-10px {
margin: 10px
}
.float {
float: left;
}
<div class="normalBox2"></div>
<div class="normalBox float"></div>
<div class="largerBox margin-10px"></div>