清除修复
通过添加 clearfix 工具,快速轻松地清除容器内的浮动内容。
通过将 .clearfix 添加到父元素,轻松清除 float。也可以用作混入。
🌐 Easily clear floats by adding .clearfix to the parent element. Can also be used as a mixin.
在 HTML 中使用:
🌐 Use in HTML:
<div class="clearfix">...</div>
mixin 源代码:
🌐 The mixin source code:
@mixin clearfix() {
&::after {
display: block;
clear: both;
content: "";
}
}
在 SCSS 中使用 mixin:
🌐 Use the mixin in SCSS:
.element {
@include clearfix;
}
以下示例展示了如何使用 clearfix。如果没有 clearfix,封装的 div 将无法围绕按钮,从而导致布局破裂。
🌐 The following example shows how the clearfix can be used. Without the clearfix the wrapping div would not span around the buttons which would cause a broken layout.
<div class="bg-info clearfix">
<button type="button" class="btn btn-secondary float-start">Example Button floated left</button>
<button type="button" class="btn btn-secondary float-end">Example Button floated right</button>
</div>