Spacings - margins and paddings

In VUD we include a wide range of shorthand responsive margins and paddings to help you modify the appearance of an element/component.

Notation

The spacing utilities can be applied to all breakpoints, from xs to xxl, or to none.

The classes are named using the format {property}{sides}-{size} (eg. .mr-24 - margin-right: 2.4rem) and {property}{sides}-{breakpoint}-{size} (eg. .mr-md-24 - margin-right: 2.4rem for screens larger than 992px) for xs, sm, md, lg, xl, and xxl.

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
  • 2 - for classes that set the margin or padding to 0.2rem (2px)
  • 4 - for classes that set the margin or padding to 0.4rem (4px)
  • 8 - for classes that set the margin or padding to 0.8rem (8px)
  • 12 - for classes that set the margin or padding to 1.2rem (12px)
  • 16 - for classes that set the margin or padding to 1.6rem (16px)
  • 24 - for classes that set the margin or padding to 2.4rem (24px)
  • 32 - for classes that set the margin or padding to 3.2rem (32px)
  • 40 - for classes that set the margin or padding to 4rem (40px)
  • 48 - for classes that set the margin or padding to 4.8rem (48px)
  • 64 - for classes that set the margin or padding to 6.4rem (64px)
  • 96 - for classes that set the margin or padding to 9.6rem (96px)
  • 128 - for classes that set the margin or padding to 12.8rem (128px)
  • auto - for classes that set the margin to auto
					
<!-- margin top: 0px -->
<div class="mt-0"> ... </div>
<!-- margin top and bottom: 8px/0.8rem -->
<div class="my-8"> ... </div>
<!-- padding right and left: 12px/1.2rem -->
<div class="px-12"> ... </div>
<!-- padding left: 12px/1.2rem for @media (min-width: $screen-lg-min) -->
<div class="pl-lg-4"> ... </div>

You are also able to use them as variables: $spacing-0, $spacing-2, $spacing-4, $spacing-8, $spacing-12, $spacing-16, $spacing-24, $spacing-32, $spacing-40, $spacing-48, $spacing-64, $spacing-96, $spacing-128, $spacing-auto

Negative margin

In CSS, margin properties can have negative values (padding cannot). The syntax for negative margins is nearly the same as the one for the positive margin, but with the addition of n before the requested size. Here’s an example class: .mt-n4 which is margin-top: -0.4rem

					
<div class="mb-n24"> ... </div>
<div class="mb-sm-n12"> ... </div>
<!-- How this clasess will look in CSS --> .mt-0 { margin-top: 0 !important; } .mr-24 { margin-right: 2.4rem !important; } .px-12 { padding-right: 1.2rem !important; padding-left: 1.2rem !important; } .p-8 { padding: 0.8rem !important; } .ml-lg-4 { @media (min-width: $screen-md-min) { margin-left: 0.4rem !important; } } .mb-n24 { margin-bottom: -2.4rem !important; }