.clearfix::before,
.clearfix::after {
content: "";
display: block;
clear: both;
}
I think the clearfix method above is both compact and safe. However, I realised that if this method is as good as I think, it should have been the most popular clearfix method, while actually it isn't widely used.
My question is: what potential problem can this clearfix bring?
Here is an example showing how it works:
.container {
background: silver;
}
.float {
float: left;
}
/* Is this safe? */
.clearfix::before,
.clearfix::after {
content: "";
display: block;
clear: both;
}
<div class="container">
<div class="float">
outer-float
</div>
<div class="clearfix">
<div class="float">
inner-float
</div>
content
</div>
</div>