nibru
1/14/2019 - 11:43 AM

css.clearfix

The clearfix Hack

If an element is taller than the element containing it, and it is floated, it will overflow outside of its container.

Then we can add overflow: auto; to the containing element to fix this problem:

Example

.clearfix {
  overflow: auto;
}

The overflow:auto clearfix works well as long as you are able to keep control of your margins and padding (else you might see scrollbars). The new, modern clearfix hack however, is safer to use, and the following code is used for most webpages:

Example

.clearfix::after {
  content: "";
  clear: both;
  display: table;
}
.clearfix::after {
    content: "";
    clear: both;
    display: block;
}