Skip to content

Instantly share code, notes, and snippets.

@azimidev
Forked from jacurtis/_spacing-helpers.scss
Last active February 5, 2020 08:59
Show Gist options
  • Save azimidev/59140633c45ff432b186ad8454bfeeeb to your computer and use it in GitHub Desktop.
Save azimidev/59140633c45ff432b186ad8454bfeeeb to your computer and use it in GitHub Desktop.
SASS Margin and Padding Helpers Loop.
/*
This .scss loop will create "margin helpers" and "padding helpers" for use in your web projects.
It will generate several classes such as:
.mr-10 which gives margin 10 pixels.
.pb-5 gives PADDING 5 pixels
The first letter is "m" or "p" for MARGIN or PADDING
Second letter is "t", "b", "l", or "r" for TOP, BOTTOM, LEFT, or RIGHT
Third letter is the number of spacing in pixels. Adjust the amounts generated by editing the $spaceamounts variable below.
*/
$spaceamounts: (5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 75, 100); // Adjust this to include the pixel amounts you need.
$sides: (top, bottom, left, right); // Leave this variable alone
@each $space in $spaceamounts {
@each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$space} {
margin-#{$side}: #{$space}px !important;
}
.p#{str-slice($side, 0, 1)}-#{$space} {
padding-#{$side}: #{$space}px !important;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment