0% completed
When elements are floated, subsequent content might wrap around them in unexpected ways. To prevent this, you clear the floats. Clearing floats makes sure that an element appears below the floated elements. This is often necessary to maintain the intended layout and prevent overlapping or misalignment of content.
Follow the code block below to clear floats in CSS:
/* Clear floats using the clear property */ clear: none | left | right | both;
Explanation:
clear: both;
In this example, we float an image to the left of some text. A subsequent <div>
clears the float so that it starts on a new line below the floated elements.
Explanation:
.float-left
..clearfix
class with clear: both;
forces subsequent content to start below the floated elements.In this example, we float two boxes: one to the left and one to the right. A <div>
that clears the left float is used to ensure the following content does not wrap around the left-floated element.
Explanation:
.clear-left
class using clear: left;
clears the left float.This lesson shows how to clear floats using the clear
property in CSS. By applying clear: both;
or clear: left/right;
, you can control the flow of your layout and maintain a clean, organized design.
.....
.....
.....