My centered header bottom margin is overflowing the parent container, causing a gap between yellow and orange wrappers:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
.header-wrap{
background-color:yellow;
}
.content-wrap{
background-color:orange;
}
.header{
margin:0 auto 1em auto;
background-color: red;
width:40em;
}
</style>
</head>
<body>
<div class="header-wrap">
<div class="header">header</div>
</div>
<div class="content-wrap">
<div class="content">content</div>
</div>
</body>
</html>
If I use a simple clearfix for parent .header-wrap{overflow:hidden;}
the problem is fixed, but I don't understand why I need to use a clearfix here, since I'm not using floating elements at all.
From what I know, the clearfix is applied on the parent to clear any floated children inside, which is not the case here.
Can anyone explain why is this happening?