Any idea why negative margins don't work on containers with clearfix applied?
Example: https://jsfiddle.net/tuotckk4/
.cf:after {
content:"";
display:block;
clear:both;
}
.col {
float: left;
width: 50%;
margin-bottom: 50px;
}
.wrapper {
margin-bottom: -50px;
}
.wrapper-alt {
margin-bottom: -50px;
overflow: hidden;
}
<div class="wrapper cf">
<div class="col">column 1</div>
<div class="col">column 2</div>
<div class="col">column 3</div>
<div class="col">column 4</div>
</div>
<p>Something at bottom</p>
<hr />
<div class="wrapper-alt">
<div class="col">column 1</div>
<div class="col">column 2</div>
<div class="col">column 3</div>
<div class="col">column 4</div>
</div>
<p>Something at bottom</p>
In first example, negative margins of -50px have no effect. In the second example, using overflow: hidden it works just fine.
I know I can use overflow: hidden but I would like to know why the bottom margin on clearfix isn't working. Is it possible to make it work without using additional wrapper element?