What does the CSS rule “clear: both” do?

前端 未结 5 1546
轮回少年
轮回少年 2020-11-21 07:42

What does the following CSS rule do:

.clear { clear: both; }

And why do we need to use it?

5条回答
  •  太阳男子
    2020-11-21 08:03

    When you want one element placed at the bottom other element you use this code in CSS. It is used for floats.

    If you float content you can float left or right... so in a common layout you might have a left nav, a content div and a footer.

    To ensure the footer stays below both of these floats (if you have floated left and right) then you put the footer as clear: both.

    This way it will stay below both floats.

    (If you are only clearing left then you only really need to clear: left;.)

    Go through this tutorial:

提交回复
热议问题