-
-
Save hachesilva/aa0d3866343075134287bb909117e39d to your computer and use it in GitHub Desktop.
This is a simple sass (rather scss) recreation of a bootstrap like spacing utility which allows you to quickly and easily set margin and padding sizes through classes like `mx-3`, `p-2`, and `pt-5`. You can define spacing values in $spacing and add or remove shorthand properties with the $prefixes variable. This uses `!important` to override any…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin simpleSpace { | |
// margin and padding values | |
$spacings: ( | |
0, | |
.25rem, | |
.5rem, | |
1rem, | |
1.5rem, | |
2rem, | |
) !default; | |
// margin and padding shorthand prefixes | |
$prefixes: ( | |
p : padding, | |
px : (padding-left, padding-right), | |
py : (padding-top, padding-bottom), | |
pt : padding-top, | |
pr : padding-right, | |
pb : padding-bottom, | |
pl : padding-left, | |
m : margin, | |
mx : (margin-left, margin-right), | |
my : (margin-top, margin-bottom), | |
mt : margin-top, | |
mr : margin-right, | |
mb : margin-bottom, | |
ml : margin-left, | |
) !default; | |
// Loop generating all spacing styles | |
@each $attr-short, $attr-list in $prefixes { | |
@each $space in $spacings { | |
.#{$attr-short}-#{ index(($spacings), $space)-1 } { | |
@each $attr in $attr-list { | |
#{$attr}: #{$space} !important; | |
} | |
} | |
} | |
} | |
} | |
@include simpleSpace(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment