Compass / Blurprint 的 +clearfix 到底有什么作用?
通常,我使用 div
来清除浮点数
<div style="clear:both"></div>
在 Compass / Blueprint 中,有一个
+clearfix
它到底有什么作用?它是否清除当前的浮动元素,而不是清除上面的浮动元素?这是否意味着如果当前元素使用+clearfix
,那么元素 那后续不用做清楚吗?实际上,我没有看到当前元素或下一个元素有任何 clear
作为使用 Firebug 的测试,那么它到底做了什么?
Ususally, I use a div
to clear the floats
<div style="clear:both"></div>
In Compass / Blueprint, there is a
+clearfix
What exactly does it do? Does it clear the current floating element, instead of clearing the floats up above? Does that mean if the current element use +clearfix
, then the elements
that follow don't have to do a clear? Actually I don't see any clear
for the current element or the next one as a test using Firebug, so what exactly does it do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在运行 v0.10.5 和
/Library/Ruby/Gems/1.8/gems/compass-0.10.5/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.scss 内容为:
这是 SCSS 语法,但它与您引用的 SASS 语法非常直接相似。
has-layout
mixin 包含在同一目录中的_hacks.scss
部分中,并且似乎特定于 IE。I'm running v0.10.5 and the source code partial in
/Library/Ruby/Gems/1.8/gems/compass-0.10.5/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.scss
reads:This is the SCSS syntax, but it's pretty directly analogous to the SASS syntax you reference. The
has-layout
mixin is included in the_hacks.scss
partial in that same directory and appears to be specific to IE.我的猜测是,它做了这样的事情:
这段代码在 element.clearfix 之后生成一个不可见的块元素,它清除了浮动。可能还需要一些额外的技巧才能使其在 IE 中工作。 8. 您不会在 Firebug 中看到任何内容,因为它不显示生成的内容。
My guess is, it does something like this:
This code generates an invisible block element after element.clearfix which clears the float. Probably there are also some additional hacks involved to make it work in IE < 8. You won't see anything in Firebug as it does not display generated content.