Bootstrap uses a default spacing scale based on multiples of 0.25rem. For example, m-1 means margin of 0.25rem, m-2 means 0.5rem, and so on.
Click to reveal answer
intermediate
How can you customize Bootstrap's spacing scale?
You can customize the spacing scale by overriding the $spacer Sass variable or by defining your own scale in the $spacers map before compiling Bootstrap's Sass files.
Click to reveal answer
intermediate
What is the purpose of the $spacers Sass map in Bootstrap?
The $spacers map defines the spacing scale values used for margin and padding utilities. Changing this map changes the sizes available for spacing classes like m-3 or p-4.
Click to reveal answer
beginner
True or False: You can modify Bootstrap spacing scale without using Sass.
False. To modify the spacing scale itself, you need to customize Bootstrap's Sass source files and recompile. You can only use the default scale with the precompiled CSS.
Click to reveal answer
intermediate
How does changing the $spacer variable affect spacing utilities?
Changing $spacer changes the base unit for spacing. For example, if $spacer is set to 4rem, then m-1 will apply 4rem margin instead of the default 0.25rem.
Click to reveal answer
What Sass variable controls the base spacing unit in Bootstrap?
A$spacer
B$spacing-scale
C$base-spacing
D$space-unit
✗ Incorrect
The $spacer variable sets the base unit for spacing in Bootstrap.
Which Sass map holds the spacing scale values for Bootstrap utilities?
A$spacing-values
B$space-map
C$spacers
D$spacing-scale
✗ Incorrect
The $spacers map defines the spacing scale used by margin and padding utilities.
If you want m-1 to apply 1rem margin instead of 0.25rem, what should you do?
AChange <code>$spacer</code> to 1rem and recompile Bootstrap Sass
BAdd a new CSS class manually
CUse inline styles instead
DModify the compiled CSS directly
✗ Incorrect
Changing $spacer to 1rem and recompiling updates the base spacing unit.
Can you modify Bootstrap's spacing scale by only editing the CSS file?
AYes, just change the CSS values
BNo, spacing scale is fixed and cannot be changed
CYes, by adding new CSS classes
DNo, you must modify Sass variables and recompile
✗ Incorrect
The spacing scale is controlled by Sass variables, so you need to modify Sass and recompile.
What happens if you add a new value to the $spacers map?
ANothing, you must also update utility generators
BBootstrap automatically creates new spacing classes for it
CIt breaks Bootstrap CSS
DIt changes the default spacing unit
✗ Incorrect
Adding new values to $spacers creates new spacing utility classes after recompiling.
Explain how to customize Bootstrap's spacing scale using Sass variables.
Think about the base unit and the scale map.
You got /4 concepts.
Describe why you cannot change Bootstrap's spacing scale by only editing the CSS file.
Consider how Bootstrap generates its utility classes.
You got /4 concepts.
Practice
(1/5)
1. What does modifying the $spacer variable in Bootstrap SCSS affect?
easy
A. The font size of all text elements
B. The color scheme of Bootstrap components
C. The base unit for spacing scale used in margin and padding classes
D. The border radius of buttons and cards
Solution
Step 1: Understand the role of $spacer
The $spacer variable sets the base size for spacing in Bootstrap, like margins and paddings.
Step 2: Identify what changes when $spacer is modified
Changing $spacer changes the size unit used in spacing utilities, affecting all related classes.
Final Answer:
The base unit for spacing scale used in margin and padding classes -> Option C
Quick Check:
$spacer controls spacing size [OK]
Hint: Remember $spacer controls spacing size, not colors or fonts [OK]
Common Mistakes:
Confusing spacing with colors or fonts
Thinking $spacer changes border radius
Assuming $spacer affects typography
2. Which of the following is the correct way to override the Bootstrap spacing scale base unit using CSS variables?
easy
A. html { --bs-spacing: 2rem; }
B. body { $spacer: 2rem; }
C. :root { $spacer: 2rem; }
D. :root { --bs-spacer: 2rem; }
Solution
Step 1: Identify how CSS variables are declared
CSS variables use the syntax --variable-name inside selectors like :root.
Step 2: Match the correct syntax for Bootstrap spacing variable
Bootstrap uses --bs-spacer as the CSS variable for spacing, so overriding it in :root is correct.
Final Answer:
:root { --bs-spacer: 2rem; } -> Option D
Quick Check:
CSS variables start with -- and use :root for global override [OK]
Hint: CSS variables start with -- and go inside :root [OK]
Common Mistakes:
Using SCSS variable syntax ($spacer) inside CSS
Placing CSS variables inside wrong selectors
Using incorrect variable names like --bs-spacing
3. Given this CSS override:
:root { --bs-spacer: 3rem; }
What will be the margin size of class="m-2" in Bootstrap?
medium
A. 1.5rem
B. 1rem
C. 0.5rem
D. 3rem
Solution
Step 1: Understand Bootstrap spacing scale
Bootstrap spacing scale uses multiples of --bs-spacer divided by 4 for each step. For m-2, margin is 0.5 * $spacer.
4. You tried to change the spacing scale by adding $spacer: 3rem; in your CSS file but it didn't work. What is the likely reason?
medium
A. A and D
B. $spacer is a SCSS variable and cannot be used directly in CSS
C. You must import Bootstrap SCSS before overriding $spacer
D. You need to use --bs-spacer instead of $spacer in CSS
Solution
Step 1: Differentiate SCSS and CSS variables
$spacer is a SCSS variable used during compilation, not valid in CSS files.
Step 2: Understand correct override methods
To override spacing in CSS, use the CSS variable --bs-spacer.
Step 3: Combine reasons for failure
Using $spacer in CSS fails because it's invalid SCSS syntax (A) and the incorrect variable name for CSS (D).
Final Answer:
A and D -> Option A
Quick Check:
SCSS vars invalid in CSS; use --bs-spacer [OK]
Hint: SCSS vars need SCSS files; CSS uses --bs-spacer [OK]
Common Mistakes:
Using SCSS variables directly in CSS
Using incorrect variable name in CSS
Confusing CSS and SCSS variable syntax
5. You want to create a custom spacing scale in Bootstrap with these values: 0, 0.25rem, 0.5rem, 1rem, 2rem, 4rem. Which SCSS code correctly modifies the spacing scale?
hard
A. $spacers: (0, 0.25rem, 0.5rem, 1rem, 2rem, 4rem);