为什么 float 后面跟着clear
向左浮动,然后向左清除是什么意思。或者向左浮动,然后向右清除?谁能帮助我理解这一点。我不是 CSS 专家,但需要了解一些我正在使用的 CSS。
#elem1{
float:left;
clear:left;
}
#elem2{
float:left;
clear:right;
}
What does it mean to float left, then clear left. Or float left, then clear right? Can anyone help me understand this. I'm not a CSS guy, but need to understand some of the CSS I'm working with.
#elem1{
float:left;
clear:left;
}
#elem2{
float:left;
clear:right;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将两个元素浮动在一起,并且不应用清除,它们将在同一水平轴上对齐。
通过告诉浮动元素清除,它会清除其之前的所有浮动元素,然后将其自身浮动到设计者想要浮动的任何位置。它是否会换一条新线,取决于清除的方向。
请参阅此 jsFiddle 示例以获取可视化效果。前两个
不清除任何内容,而最后两个
设置为清除左右浮动。
If you float two elements together, they will align on the same horizontal axis if you don't apply clearing.
By telling a floating element to clear, it clears any floats that come before it, then floats itself wherever the designer intends to float it. It will go on a new line, or not, depending on the direction of the clear.
See this jsFiddle example for a visualization. The first two
<div>
s don't clear anything, while the last two<div>
s are set to clear both left and right floats.clear
表示将元素定位在任何先前浮动元素的下方,以“清除线条”。通常浮动元素会像这样堆积在同一行:
清除它们之前的所有浮动元素将使它们排列如下:
clear
means to position the element below any previous floating elements, to "clear the line".Usually floating elements pile up on the same line like this:
Making them clear any previous floating elements will make them arrange like this:
这里可以更清楚地了解为什么需要清除。 http://www.quirksmode.org/css/clearing.html
Here is a clearer view of why a clear is needed. http://www.quirksmode.org/css/clearing.html