在 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>