I just learnt a new "css hack" from my teacher. But he don't know why it works.
I'll explain:
I've on my website a gap (the green line) which I don't want to appear:
the grey one is the nav element, the black is a div which contains the p-tag "some content" which make this gap because of his margin. (I'll post the code at the end of the question).
My solution would be just delete the margin. But my teacher telled me another way. He added overflow: hidden;
to the div which contains the p, and poff, the gap is gone.
But how is this possible? Why do overflow affect the margin of an element?
Here's a example code plus a codepen demo:
http://codepen.io/anon/pen/JdQaYv
.container,
.header,
.content{
margin 0;
padding: 0;
}
.container{
background; green;
}
.header{
background: red;
}
.content{
background: yellow;
}
.overflow{
overflow: hidden;
}
<div class="container">
<div class="header">
Header
</div>
<div class="content">
<p>Contentcontent</p>
</div>
</div>
___________________________________________
<br />
<div class="container">
<div class="header">
Header
</div>
<div class="content overflow">
<p>Contentcontent</p>
</div>
</div>