Easily clear floats by adding .clearfix to the parent element. Can also be used as a mixin.

    Use in HTML:

    1. <div class="clearfix">...</div>

    The mixin source code:

    1. @mixin clearfix() {
    2. &::after {
    3. display: block;
    4. clear: both;
    5. content: "";
    6. }
    7. }

    Use the mixin in SCSS:

    1. .element {
    2. @include clearfix;
    3. }

    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.

    Clearfix - 图1

    1. <div class="bg-info clearfix">
    2. <button type="button" class="btn btn-secondary float-start">Example Button floated left</button>
    3. <button type="button" class="btn btn-secondary float-end">Example Button floated right</button>
    4. </div>