Given a div with a child element that have a top margin, why the margin is not inside the parent div but outside ?
HTML
<div><h1>Titre<h1></div>
CSS
h1 { margin: 20px; }
div { background-color: #DDD; }
Given a div with a child element that have a top margin, why the margin is not inside the parent div but outside ?
HTML
<div><h1>Titre<h1></div>
CSS
h1 { margin: 20px; }
div { background-color: #DDD; }
That's due to collapsing margins. To fix it add overflow:auto to your div:
div {
background-color:#DDD;
overflow:auto;
}