清除浮动
通过为父元素添加.clearfix
类可以很容易地清除浮动(float
)。如:
<div class="clearfix">...</div>
这里所使用的.clearfix
类是 Nicolas Gallagher 创造的micro clearfix方式。并且,.clearfix
类还可以作为 mixin 使用。如:
// 类的Mixin定义
.clearfix() {
&:before,
&:after {
content: " ";
display: table;
}
&:after {
clear: both;
}
}
// 作为 mixin 使用
.element {
.clearfix();
}
关于作者
歪脖先生,十五年以上软件开发经验,酷爱Web开发,精通 HTML、CSS、JavaScript、jQuery、JSON、Python、Less、Bootstrap等,著有《HTML宝典》、《揭秘CSS》、《Less简明教程》、《JSON教程》、《Bootstrap2用户指南》、《Bootstrap3实用教程》,并全部在 GitHub 上开源。