Responsive spacers #41111
Replies: 3 comments
-
Hey! The Bootstrap spacing scale ( Just to clarify your requirement, are you looking to modify only the spacing utilities (like If you're focusing only on utilities, you can leverage the Utilities API alongside Sass overrides to achieve this. However, if your goal is to include components as well, the task becomes more complex. You'd likely need to integrate custom properties in multiple places—some of which might not currently exist or are inconsistently implemented across Bootstrap components. I haven't looked into the details of how to achieve that, but this is my initial impression based on your question. |
Beta Was this translation helpful? Give feedback.
-
Hey @julien-deramond, Thanks for the quick response! Let me explain the prefered situation, for example: We are using utilities like Hopefully the situation above is clear enough! 🙂 |
Beta Was this translation helpful? Give feedback.
-
I quickly tested a solution, and one approach could look like this. Hopefully, it helps you find a more suitable solution on your side: $spacer: 1rem !default;
/* New stuff */
:root {
--#{$prefix}spacer-0: 0;
--#{$prefix}spacer-1: calc(#{$spacer} * .25); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-2: calc(#{$spacer} * .5); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-3: #{$spacer};
--#{$prefix}spacer-4: calc(#{$spacer} * 1.5); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-5: calc(#{$spacer} * 3); // stylelint-disable-line function-disallowed-list
/* Let's say that under 300px, all the spacings have half the value */
@media (max-width: 300px) { /* You can probably use the Sass mixins/functions provided by Bootstrap instead to have the real values */
--#{$prefix}spacer-0: 0;
--#{$prefix}spacer-1: calc(.5 * #{$spacer} * .25); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-2: calc(.5 * #{$spacer} * .5); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-3: calc(.5 * #{$spacer}); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-4: calc(.5 * #{$spacer} * 1.5); // stylelint-disable-line function-disallowed-list
--#{$prefix}spacer-5: calc(.5 * #{$spacer} * 3); // stylelint-disable-line function-disallowed-list
}
}
/* Redefine content of `$spacers` */
$spacers: (
0: var(--#{$prefix}spacer-0),
1: var(--#{$prefix}spacer-1),
2: var(--#{$prefix}spacer-2),
3: var(--#{$prefix}spacer-3),
4: var(--#{$prefix}spacer-4),
5: var(--#{$prefix}spacer-5)
) !default; In this setup, we define custom properties for breakpoints, and I'm not 100% sure because I haven't checked too much, but I think it's kind of safe for components as well because if I remember well, we don't use |
Beta Was this translation helpful? Give feedback.
-
Hey!
I'd like to have different spacers for mobile and desktop, for example the mobile spacer '1' needs to be 8px, and desktop needs to be 16px. Is this possible in the boostrap variables file or do I need a different solution?
Beta Was this translation helpful? Give feedback.
All reactions