Generate Boostrap like CSS spacing classes using SASS.
According to the documentation of Bootstrap 4 its spacing classes have the following format:
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 setmarginp- for classes that setpadding
Where sides is one of:
t- for classes that setmargin-toporpadding-topb- for classes that setmargin-bottomorpadding-bottoml- for classes that setmargin-leftorpadding-leftr- for classes that setmargin-rightorpadding-rightx- for classes that set both*-leftand*-righty- for classes that set both*-topand*-bottom- blank - for classes that set a
marginorpaddingon all 4 sides of the element
Where size is one of:
0- for classes that eliminate themarginorpaddingby setting it to01- (by default) for classes that set themarginorpaddingto$spacer * .252- (by default) for classes that set themarginorpaddingto$spacer * .53- (by default) for classes that set themarginorpaddingto$spacer4- (by default) for classes that set themarginorpaddingto$spacer * 1.55- (by default) for classes that set themarginorpaddingto$spacer * 3auto- for classes that set themarginto auto
Our focus is to generate all the css classes of the format {property}{sides}-{size}.
For example:
m-0tom-5andm-autop-0top-5mt-0,mb-0,ml-0,mr-0tomt-5,mb-5,ml-5,mr-5andmt-auto,mb-auto,ml-auto,mr-autopt-0,pb-0,pl-0,pr-0topt-5,pb-5,pl-5,pr-5mx-0tomx-5andmy-0tomy-5andmx-auto,my-autopx-0topx-5andpy-0tomy-5
Notice, we are omitting {property}{sides}-{breakpoint}-{size} pattern, which is not in the scope of this project.
If your project setup supports scss file, then you can copy the _spacing.scss file from the src directory into your project and import this file into your root style file using @use rule.
// styles.scss file, in the same directory of _spaces.scss
@use "./spaces";If you need compiled css, then you can copy the generated spacing.css file from the dist directory. However, you can install SASS on your machine and use the following command to generate spaces.css file by yourself.
sass _spaces.scss spaces.css