How does CSS clearing really work?

I have a `
` that I want to be on a line by itself. According to W3Schools, this rule: div.foo { clear: both; } ...should mean this: > "No floating elements allowed on either the left or the right side." However, if I float two `
` elements left, and apply the rule above to the first one, the second one does not budge. On the other hand, if I apply `"clear: left"` to the second `
`, it moves down to the next line. This is my normal approach, but I don't understand why I have to do it like this. Is the W3Schools description above poorly stated, or am I missing something? **Is a clearing rule only able to move the element to which it is applied?** Answer - Thanks Michael S and John D for the good explanations. Warren pointed to the CSS2 spec, and that's where I found this answer (emphasis mine): > This property indicates which sides of an element's box(es) may not be adjacent to an **earlier** floating box. So: `clear` only affects the position of the element to which it is applied, relative to elements that appear before it the code. Disappointing that I can't tell my `
` to make other divs move down, but them's the breaks. :)
> Disappointing that I can't tell my
to make other divs move > down, but them's the breaks. Then why use float at all?

以上就是How does CSS clearing really work?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏