I wanted to update this topic since I encountered more problems than solutions importing the Bootstrap 5 source and referencing those source files in my custom.scss file.
- Exporting and publishing takes a lot longer due to all of the added SCSS files.
- My page layouts looked fine in the editor and in preview mode, but were broken when viewing a published version. I’m guessing that the imported SCSS files might be conflicting with the core files. This is probably fixable, but more work than needed.
I did manage to find a more elegant solution though. My custom.scss file doesn’t need any external files now and I can define custom spacers as needed. This was solved by defining $spacers and $breakpoints directly in the file instead of importing them, and no external files needed to be imported.
The updated custom.scss file is shown below. In the $spacers array, 1-5 are commented and only shown for reference. They are not needed, since 1-5 are already defined in Bootstrap. This creates 6-12 spacers (ex: mb-7 mb-lg-10 mb-xxl-11).
// Spacers (6-12 are custom spacers)
$spacers: (
/0: 0rem,
1: .25rem,
2: .5rem,
3: 1rem,
4: 1.5rem,
5: 3rem,/
6: 4rem,
7: 5rem,
8: 6rem,
9: 7rem,
10: 8rem,
11: 9rem,
12: 10rem
);
// Bootstrap-5 default breakpoints
$breakpoints: (
‘xs’: ‘screen and (min-width: 0px)’,
‘sm’: ‘screen and (min-width: 576px)’,
‘md’: ‘screen and (min-width: 768px)’,
‘lg’: ‘screen and (min-width: 992px)’,
‘xl’: ‘screen and (min-width: 1200px)’,
‘xxl’: ‘screen and (min-width: 1400px)’
);
// Non-breakpoint spacers (ex: mb-2)
@each $spacer, $size in $spacers {
.m-#{$spacer} { margin: $size !important; }
.mt-#{$spacer} { margin-top: $size !important; }
.mb-#{$spacer} { margin-bottom: $size !important; }
.mr-#{$spacer} { margin-right: $size !important; }
.ml-#{$spacer} { margin-left: $size !important; }
.mx-#{$spacer} { margin-left: $size !important; margin-right: $size !important; }
.my-#{$spacer} { margin-top: $size !important; margin-bottom: $size !important; }
}
// Breakpoint spacers (ex: mb-xl-5)
@each $spacer, $size in $spacers {
@each $breakpoint, $media-query in $breakpoints {
@media #{$media-query} {
.m-#{$breakpoint}-#{$spacer} { margin: $size !important; }
.mt-#{$breakpoint}-#{$spacer} { margin-top: $size !important; }
.mb-#{$breakpoint}-#{$spacer} { margin-bottom: $size !important; }
.mr-#{$breakpoint}-#{$spacer} { margin-right: $size !important; }
.ml-#{$breakpoint}-#{$spacer} { margin-left: $size !important; }
.mx-#{$breakpoint}-#{$spacer} { margin-left: $size !important; margin-right: $size !important; }
.my-#{$breakpoint}-#{$spacer} { margin-top: $size !important; margin-bottom: $size !important; }
}
}
}
Thanks,
Todd