How does the clear in CSS work?

The clear property works with respect to float property. It sets whether an element must be moved below the floating elements that precede it.

Let’s understand this with the help of an example.

We will consider four blocks red, yellow, blue…


This content originally appeared on DEV Community and was authored by Jasmin Virdi

The clear property works with respect to float property. It sets whether an element must be moved below the floating elements that precede it.

Let's understand this with the help of an example.

We will consider four blocks red, yellow, blue and green which will be added one after the other and they all will be placed at same level.

Adding blocks

Then we will make each element float to left one by one which means they will be moved one level above their initial position. This will allow other non floating elements to wrap around the floating element.

floating blocks

Note - The next block will occupy the position of the floating block that is why it is not visible. When we change the dimension of next block we observe that it is covered with floating block which is present one layer above it.

After this we will apply clear:left to blue block which means that no element will be floating to the left of blue block.

Clear blocks

With the help of clear property we can specify that which side of floating elements are not allowed to float. It sets or return the position with respect to the floating objects.

Values accepted in clear property.

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;

You can find the code here

I tried to cover the working of CSS clear property using a basic example for better understanding. Please share your examples and feel to add up to this post 😊

Happy Learning!👩🏻‍💻


This content originally appeared on DEV Community and was authored by Jasmin Virdi


Print Share Comment Cite Upload Translate Updates
APA

Jasmin Virdi | Sciencx (2022-05-07T18:17:03+00:00) How does the clear in CSS work?. Retrieved from https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/

MLA
" » How does the clear in CSS work?." Jasmin Virdi | Sciencx - Saturday May 7, 2022, https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/
HARVARD
Jasmin Virdi | Sciencx Saturday May 7, 2022 » How does the clear in CSS work?., viewed ,<https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/>
VANCOUVER
Jasmin Virdi | Sciencx - » How does the clear in CSS work?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/
CHICAGO
" » How does the clear in CSS work?." Jasmin Virdi | Sciencx - Accessed . https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/
IEEE
" » How does the clear in CSS work?." Jasmin Virdi | Sciencx [Online]. Available: https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/. [Accessed: ]
rf:citation
» How does the clear in CSS work? | Jasmin Virdi | Sciencx | https://www.scien.cx/2022/05/07/how-does-the-clear-in-css-work/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.