The clear
property works with respect to float
property. It determines whether an element must be moved below the floating elements that precede it.
Let's understand the clear
property with an example.
The next block will occupy the position of the floating block due to which it is not visible. When we change the dimension of the next block we observe that it is covered with a floating block which is present one layer above it
clear:left
to the blue block, which means that no element will be floating to the left of the blue block.With the help of the clear
property, we can specify which side of floating elements are not allowed to float. It sets or returns the position with respect to the floating objects.
clear: none;clear: left;clear: right;clear: both;clear: inline-start;clear: inline-end;clear: inherit;clear: initial;clear: revert;clear: revert-layer;clear: unset;
Let's have a look at the below example:
We create 4 <div>
elements wrapped inside the parent wrapper. Each <div>
represents the colored blocks, which are red, yellow, blue, and green.
In the CSS file, we assign the float:left
property to each block along with clear:both
assigning it to the blue block. This helps to show the correlation between the float and clear property and position element with respect to it.
Free Resources