Clearfix

Quickly and easily clear floated content within a container by adding a clearfix utility.

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

  1. <div class="clearfix">...</div>
  1. // Mixin itself
  2. @mixin clearfix() {
  3. &::after {
  4. display: block;
  5. content: "";
  6. clear: both;
  7. }
  8. }
  9. // Usage as a mixin
  10. .element {
  11. @include clearfix;
  12. }

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-left">Example Button floated left</button>
  3. <button type="button" class="btn btn-secondary float-right">Example Button floated right</button>
  4. </div>