Skip to content

Instantly share code, notes, and snippets.

@lazabogdan
Last active August 14, 2020 18:10
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save lazabogdan/6878954076420348fb4f to your computer and use it in GitHub Desktop.
Save lazabogdan/6878954076420348fb4f to your computer and use it in GitHub Desktop.
Sass spacing utility
// ----
// libsass (v3.3.2)
// ----
$spacer: 1rem;
$spacer-x: $spacer;
$spacer-y: $spacer;
$spacers: ();
@for $i from 0 through 3 {
$spacers: map-merge($spacers, (
$i: (
x: $spacer-x * $i,
y: $spacer-y * $i
)
))
}
@each $prop, $abbrev in (margin: m, padding: p) {
@each $size, $lengths in $spacers {
$length-x: map-get($lengths, x);
$length-y: map-get($lengths, y);
.#{$abbrev}-a-#{$size} { #{$prop}: $length-y $length-x !important; } // a = All sides
.#{$abbrev}-t-#{$size} { #{$prop}-top: $length-y !important; }
.#{$abbrev}-r-#{$size} { #{$prop}-right: $length-x !important; }
.#{$abbrev}-b-#{$size} { #{$prop}-bottom: $length-y !important; }
.#{$abbrev}-l-#{$size} { #{$prop}-left: $length-x !important; }
// Axes
.#{$abbrev}-x-#{$size} {
#{$prop}-right: $length-x !important;
#{$prop}-left: $length-x !important;
}
.#{$abbrev}-y-#{$size} {
#{$prop}-top: $length-y !important;
#{$prop}-bottom: $length-y !important;
}
}
}
.m-a-0 {
margin: 0rem 0rem !important;
}
.m-t-0 {
margin-top: 0rem !important;
}
.m-r-0 {
margin-right: 0rem !important;
}
.m-b-0 {
margin-bottom: 0rem !important;
}
.m-l-0 {
margin-left: 0rem !important;
}
.m-x-0 {
margin-right: 0rem !important;
margin-left: 0rem !important;
}
.m-y-0 {
margin-top: 0rem !important;
margin-bottom: 0rem !important;
}
.m-a-1 {
margin: 1rem 1rem !important;
}
.m-t-1 {
margin-top: 1rem !important;
}
.m-r-1 {
margin-right: 1rem !important;
}
.m-b-1 {
margin-bottom: 1rem !important;
}
.m-l-1 {
margin-left: 1rem !important;
}
.m-x-1 {
margin-right: 1rem !important;
margin-left: 1rem !important;
}
.m-y-1 {
margin-top: 1rem !important;
margin-bottom: 1rem !important;
}
.m-a-2 {
margin: 2rem 2rem !important;
}
.m-t-2 {
margin-top: 2rem !important;
}
.m-r-2 {
margin-right: 2rem !important;
}
.m-b-2 {
margin-bottom: 2rem !important;
}
.m-l-2 {
margin-left: 2rem !important;
}
.m-x-2 {
margin-right: 2rem !important;
margin-left: 2rem !important;
}
.m-y-2 {
margin-top: 2rem !important;
margin-bottom: 2rem !important;
}
.m-a-3 {
margin: 3rem 3rem !important;
}
.m-t-3 {
margin-top: 3rem !important;
}
.m-r-3 {
margin-right: 3rem !important;
}
.m-b-3 {
margin-bottom: 3rem !important;
}
.m-l-3 {
margin-left: 3rem !important;
}
.m-x-3 {
margin-right: 3rem !important;
margin-left: 3rem !important;
}
.m-y-3 {
margin-top: 3rem !important;
margin-bottom: 3rem !important;
}
.p-a-0 {
padding: 0rem 0rem !important;
}
.p-t-0 {
padding-top: 0rem !important;
}
.p-r-0 {
padding-right: 0rem !important;
}
.p-b-0 {
padding-bottom: 0rem !important;
}
.p-l-0 {
padding-left: 0rem !important;
}
.p-x-0 {
padding-right: 0rem !important;
padding-left: 0rem !important;
}
.p-y-0 {
padding-top: 0rem !important;
padding-bottom: 0rem !important;
}
.p-a-1 {
padding: 1rem 1rem !important;
}
.p-t-1 {
padding-top: 1rem !important;
}
.p-r-1 {
padding-right: 1rem !important;
}
.p-b-1 {
padding-bottom: 1rem !important;
}
.p-l-1 {
padding-left: 1rem !important;
}
.p-x-1 {
padding-right: 1rem !important;
padding-left: 1rem !important;
}
.p-y-1 {
padding-top: 1rem !important;
padding-bottom: 1rem !important;
}
.p-a-2 {
padding: 2rem 2rem !important;
}
.p-t-2 {
padding-top: 2rem !important;
}
.p-r-2 {
padding-right: 2rem !important;
}
.p-b-2 {
padding-bottom: 2rem !important;
}
.p-l-2 {
padding-left: 2rem !important;
}
.p-x-2 {
padding-right: 2rem !important;
padding-left: 2rem !important;
}
.p-y-2 {
padding-top: 2rem !important;
padding-bottom: 2rem !important;
}
.p-a-3 {
padding: 3rem 3rem !important;
}
.p-t-3 {
padding-top: 3rem !important;
}
.p-r-3 {
padding-right: 3rem !important;
}
.p-b-3 {
padding-bottom: 3rem !important;
}
.p-l-3 {
padding-left: 3rem !important;
}
.p-x-3 {
padding-right: 3rem !important;
padding-left: 3rem !important;
}
.p-y-3 {
padding-top: 3rem !important;
padding-bottom: 3rem !important;
}
@iamsean007
Copy link

This is just awesome!!! Just what I needed, now I don't have to import Bootstrap

Thanks again @lazabogdan

@mx-rk-quyenl
Copy link

Thank you,
You save my day bro 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment