Performance: Modifying spacing scale
Modifying the spacing scale affects CSS file size and rendering speed by changing how many utility classes are generated and used.
$spacers: (0: 0, 1: 0.25rem, 2: 0.5rem, 3: 1rem, 4: 1.5rem, 5: 3rem, 6: 5rem);
$spacers: (0: 0, 1: 0.25rem, 2: 0.5rem, 3: 1rem, 4: 1.5rem, 5: 2rem, 6: 3rem, 7: 4rem, 8: 5rem, 9: 6rem, 10: 7rem, 11: 8rem);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large spacing scale with many utilities | No extra DOM nodes | No extra reflows | High paint cost due to large CSS | [X] Bad |
| Minimal spacing scale with essential utilities | No extra DOM nodes | No extra reflows | Low paint cost with smaller CSS | [OK] Good |
$spacer variable in Bootstrap SCSS affect?$spacer$spacer variable sets the base size for spacing in Bootstrap, like margins and paddings.$spacer is modified$spacer changes the size unit used in spacing utilities, affecting all related classes.$spacer controls spacing size [OK]--variable-name inside selectors like :root.--bs-spacer as the CSS variable for spacing, so overriding it in :root is correct.:root { --bs-spacer: 3rem; }class="m-2" in Bootstrap?--bs-spacer divided by 4 for each step. For m-2, margin is 0.5 * $spacer.--bs-spacer: 3rem, m-2 margin = 3rem * 0.5 = 1.5rem.$spacer: 3rem; in your CSS file but it didn't work. What is the likely reason?$spacer is a SCSS variable used during compilation, not valid in CSS files.--bs-spacer.$spacer in CSS fails because it's invalid SCSS syntax (A) and the incorrect variable name for CSS (D).$spacers as a map with keys for each step.(0: 0, 1: 0.25rem, ...).Pass the test and this pattern moves unknown