This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.
Smartphone icons created by Freepik - Flaticon
The
property specifies what elements can float beside the cleared element and on which side. The property can have one of the following values:The most common way to use the
property is after you have used a property on an element.When clearing floats, you should match the clear to the float: If an element is floated to the left, then you should clear to the left. Your floated element will continue to float, but the cleared element will appear below it on the web page. The following example clears the float to the left. Means that no floating elements are allowed on the left side (of the div):
div { clear: left; }
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:
.clearfix { overflow: auto; }
The
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:.clearfix::after { content: ""; clear: both; display: table; }
You will learn more about the
pseudo-element in a later chapter.