Challenge - 5 Problems
Spacing Scale Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output CSS of this Sass spacing scale?
Given the Sass code below, what is the generated CSS for the
.spacing-3 class?$spacing-scale: (0, 0.25rem, 0.5rem, 1rem, 2rem);
.spacing-3 {
margin: nth($spacing-scale, 4);
}SASS
$spacing-scale: (0, 0.25rem, 0.5rem, 1rem, 2rem); .spacing-3 { margin: nth($spacing-scale, 4); }
Attempts:
2 left
💡 Hint
Remember that
nth() starts counting from 1 in Sass lists.✗ Incorrect
The
$spacing-scale list has values indexed from 1 to 5. The 4th value is 1rem, so margin: nth($spacing-scale, 4); outputs margin: 1rem;.🧠 Conceptual
intermediate2:00remaining
How does Sass map spacing scale keys to values?
Consider this Sass map:
Which Sass function correctly retrieves the value for
$spacing-map: ( small: 0.5rem, medium: 1rem, large: 2rem );
Which Sass function correctly retrieves the value for
medium?Attempts:
2 left
💡 Hint
Map keys are strings or identifiers and need quotes if strings.
✗ Incorrect
The
map-get() function retrieves a value by key from a Sass map. Since medium is an identifier key, it is accessed without quotes. Option B is correct.❓ selector
advanced2:00remaining
Which selector applies spacing scale with Sass @each loop?
Given this Sass code:
What is the correct CSS output for the class
$spacing-scale: (0, 0.25rem, 0.5rem, 1rem);
@each $space in $spacing-scale {
.m-#{$space} {
margin: $space;
}
}What is the correct CSS output for the class
.m-0.5rem?Attempts:
2 left
💡 Hint
CSS class names cannot contain unescaped dots.
✗ Incorrect
Sass escapes the dot in
0.5rem when used in selectors, so the class becomes .m-0\.5rem in CSS. This is the valid selector.❓ layout
advanced2:00remaining
How to create a responsive spacing scale with Sass and CSS variables?
Which Sass snippet correctly generates CSS variables for spacing scale that change at a breakpoint?
$spacing-scale: (0: 0, 1: 0.5rem, 2: 1rem);
:root {
@each $key, $value in $spacing-scale {
--space-#{$key}: #{$value};
}
}
@media (min-width: 40rem) {
:root {
--space-1: 1rem;
--space-2: 2rem;
}
}Attempts:
2 left
💡 Hint
CSS variables can be redefined inside media queries for responsiveness.
✗ Incorrect
The Sass code creates CSS variables for spacing in :root and redefines some inside a media query at 40rem. This allows spacing to adapt responsively.
❓ accessibility
expert2:00remaining
How to ensure spacing scale changes do not break accessibility?
When generating spacing scales in Sass for margins and paddings, which practice best supports accessibility and user preferences?
Attempts:
2 left
💡 Hint
Accessibility benefits from scalable units and respecting user settings.
✗ Incorrect
Using rem units with CSS variables allows spacing to scale with user font size preferences and zoom, improving accessibility. Fixed px values ignore user settings and can cause layout issues.