I have floated some elements and to make the layout appear proper. I have two ways basically clear-fix and clear:both at the following element.
1)
.extra-float-container::after{
content: "";
clear: both;
display: block;
}
footer {
clear: both;
background-color: #ff0;
padding: 10px;
}
I can’t able understand why there are two ways to that. Is there any special use-cases for each of them so that other option doesn’t work?
2
Answers
clearfix is a add-on class with
clear: both
property to clear floating of an element.While
clear: both
itself a property to clear floating of both side of an element.Float was used when there were no flex or grid properties available.
You can use flex or grid layout to achieve your design.
Hope, this will help.
These two techniques achieve similar outcomes, with subtle differences. Personally if a simple
clear: both
works for a particular layout, then it would be my first choice. But there may be layouts for which the clearfix hack works better, in which case I would use that.Here is a snippet which illustrates the differences.