在 GitHub 上查看
清除浮动
通过添加清除浮动实用工具,可以快速轻松地清除容器内的浮动内容。
通过向父元素添加 .clearfix
可以轻松清除 float
。也可以用作混合。
<div class="clearfix">...</div>
// Mixin itself
@mixin clearfix() {
&::after {
display: block;
content: "";
clear: both;
}
}
// Usage as a mixin
.element {
@include clearfix;
}
以下示例展示了如何使用清除浮动。如果没有清除浮动,则包裹的 div 将不会跨越按钮,这会导致布局损坏。
<div class="bg-info clearfix">
<button type="button" class="btn btn-secondary float-left">Example Button floated left</button>
<button type="button" class="btn btn-secondary float-right">Example Button floated right</button>
</div>