Spacing

Front includes a wide range of shorthand responsive margin and padding utility classes to modify an element's appearance.

How it works

Assign responsive-friendly margin or padding values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties.

Notation

Spacing utilities that apply to all breakpoints, from xs to xl, have no breakpoint abbreviation in them. This is because those classes are applied from min-width: 0 and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.

The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.

Where property is one of:

  • m - for classes that set margin
  • p - for classes that set padding

Where sides is one of:

  • t - for classes that set margin-top or padding-top
  • b - for classes that set margin-bottom or padding-bottom
  • l - for classes that set margin-left or padding-left
  • r - for classes that set margin-right or padding-right
  • x - for classes that set both *-left and *-right
  • y - for classes that set both *-top and *-bottom
  • blank - for classes that set a margin or padding on all 4 sides of the element

Where size is one of:

  • 0 - for classes that eliminate the margin or padding by setting it to 0
  • 1 - (by default) for classes that set the margin or padding to $spacer * .25
  • 2 - (by default) for classes that set the margin or padding to $spacer * .5
  • 3 - (by default) for classes that set the margin or padding to $spacer
  • 4 - (by default) for classes that set the margin or padding to $spacer * 1.5
  • 5 - (by default) for classes that set the margin or padding to $spacer * 2
  • 6 - (by default) for classes that set the margin or padding to $spacer * 2.5
  • 7 - (by default) for classes that set the margin or padding to $spacer * 3
  • 8 - (by default) for classes that set the margin or padding to $spacer * 3.5
  • 9 - (by default) for classes that set the margin or padding to $spacer * 4
  • 10 - (by default) for classes that set the margin or padding to $spacer * 4.5
  • 11 - (by default) for classes that set the margin or padding to $spacer * 5
  • auto - for classes that set the margin to auto

(You can add more sizes by adding entries to the $spacers Sass map variable via: _theme-variables.scss.)


The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.

Where property is:

  • space - for class that set padding-top and padding-bottom

Where sides is:

  • space-top - for class that set padding-top
  • space-bottom - for class that set padding-bottom
  • blank - for classes that set a padding on top and bottom sides of the element

Where size is one of:

  • 0 - for classes that eliminate the padding-top and padding-bottom by setting it to 0
  • 1 - (by default) for classes that set the padding-top and padding-bottom to $content-space * 2
  • 2 - (by default) for classes that set the padding-top and padding-bottom to $content-space * 4
  • 3 - (by default) for classes that set the padding-top and padding-bottom to $content-space * 8
  • 4 - (by default) for classes that set the padding-top and padding-bottom to $content-space * 12.5
  • 5 - (by default) for classes that set the padding-top and padding-bottom to $content-space * 15

(You can add more sizes by adding entries to the $content-space Sass map variable via: _theme-variables.scss.)

Offset spacings

Front includes several offset classes, like:

                
                  <div class="ml-n2">.ml-n2</div>
                  <div class="ml-n3">.ml-n3</div>
                  <div class="mr-n2">.mr-n2</div>
                  <div class="mt-n1">.mt-n1</div>
                  <div class="mt-n5">.mt-n5</div>
                  <div class="mt-n6">.mt-n6</div>
                  <div class="mt-n9">.mt-n9</div>
                  <div class="mt-n23">.mt-n23</div>
                  <div class="mb-n9">.mb-n9</div>
                
              

Gutters

As well as gutters.

                
                  <div class="mx-gutters-1">.mx-gutters-1</div>
                  <div class="mx-gutters-2">.mx-gutters-2</div>
                
              

Examples

Here are some representative examples of these classes:

                
                  .mt-0 {
                    margin-top: 0 !important;
                  }

                  .ml-1 {
                    margin-left: ($spacer * .25) !important;
                  }

                  .px-2 {
                    left: ($spacer * .5) !important;
                    padding-right: ($spacer * .5) !important;
                  }

                  .p-3 {
                    padding: $spacer !important;
                  }
                
              

Horizontal centering

Additionally, Front also includes an .mx-auto class for horizontally centering fixed-width block level content—that is, content that has display: block and a width set—by setting the horizontal margins to auto.

Centered element
                      
                        <div class="mx-auto bg-primary text-white" style="width: 200px;">
                          Centered element
                        </div>
                      
                    
Contact Us