What is clearfix in CSS?
A parent element does not grow around its floated children, so it can collapse to zero height. The clearfix is a small class that fixes this.
.clearfix::after {
content: "";
display: table;
clear: both;
}
Add the class to the parent. The modern ways are overflow: auto or display: flow-root on the parent, or using Flexbox instead of float. See CSS Float and Clear.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Layout – The display Property |
| CSS Position Property |
| CSS z-index |
| CSS Float and Clear Property |
| Exercises & Assignments |
|---|
| Write CSS to centre a box horizontally using margin auto |
| Write CSS to create a horizontal navigation menu |