How does CSS clearing really work?

前端 未结 5 1292
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 03:12

I have a

that I want to be on a line by itself. According to W3Schools, this rule:

div.foo {
  clear: both;
}

...s

5条回答
  •  被撕碎了的回忆
    2020-12-30 03:46

    When you apply clear to an element, it will move THAT element so that it doesn't have items left or right of it. It does not re-position any of the other elements, it simply moves the element to a position where nothing is around it.

    Edit

    Items above the item cleared are not moved, items below the element COULD be moved. Also note the additional comment in the comments

提交回复
热议问题