If you want to customize the spacing options in your Sass file, you can add new sizes to the $spacers
map.
The original $spacer
variables/map can be found in _variables.scss
...
$spacer: 1rem !default;
$spacers: () !default;
$spacers: map-merge(
(
0: 0,
1: ($spacer * .25),
2: ($spacer * .5),
3: $spacer,
4: ($spacer * 1.5),
5: ($spacer * 3)
),
$spacers
);
To add a new size (6th size) to this map, you would need to include...
$spacers: map-merge(
(
6: ($spacer * 2.5)
),
$spacers
);
Ensure that you import it after the _functions.scss
, _variables.scss
, and _mixins.scss
files, but before other Bootstrap sass files.
Here is an example of how to include it:
// import bootstrap 4 src files
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins";
$spacers: map-merge(
(
6: ($spacer * 2.5)
),
$spacers
);
@import "~bootstrap/scss/root";
@import "~bootstrap/scss/reboot";
...
This hypothetical scenario suggests placing the new 40px (2.5)
margin/padding utility class between the existing default 4
and 5
classes.
You may need to update any current uses of the 5
classes to 6
, making the new 40px (2.5)
class now become 5
.
$spacers: map-merge(
(
5: ($spacer * 2.5),
6: ($spacer * 3)
),
$spacers
);
It's uncertain if this change will impact anything beyond margin and padding utility classes. It has not been thoroughly tested.