Challenge - 5 Problems
Spacing Utility 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 code?
Given the following SASS code that generates margin utilities, what is the compiled CSS output for
.m-2?SASS
@mixin generate-spacing($property, $sizes) { @each $name, $size in $sizes { .#{$property}-#{$name} { #{$property}: #{$size}; } } } $sizes: ( 1: 0.25rem, 2: 0.5rem, 3: 1rem ); @include generate-spacing('m', $sizes);
Attempts:
2 left
💡 Hint
Look at how the mixin uses the $property and $sizes map to create classes.
✗ Incorrect
The mixin loops through the $sizes map and creates classes with the property name and size key. For 'm' and key '2', it sets margin: 0.5rem.
🧠 Conceptual
intermediate1:30remaining
Which SASS feature allows dynamic generation of spacing utilities?
You want to create multiple spacing utility classes like
.p-1, .p-2, etc., without writing each class manually. Which SASS feature helps you do this efficiently?Attempts:
2 left
💡 Hint
Think about repeating code for multiple values.
✗ Incorrect
The @each loop lets you iterate over a map or list to generate multiple classes dynamically.
❓ selector
advanced1:30remaining
Which selector is generated by this SASS snippet?
Consider this SASS code snippet:
$sizes: (small: 0.5rem, medium: 1rem);
@mixin spacing($property) {
@each $name, $value in $sizes {
.#{$property}-#{$name} {
#{$property}: $value;
}
}
}
@include spacing('p');
Which CSS selector will be generated?
Attempts:
2 left
💡 Hint
Look at how the class name is constructed using interpolation.
✗ Incorrect
The class name is built by combining the property string and the key from the map with a hyphen.
❓ layout
advanced1:00remaining
What visual effect does this spacing utility have?
Given the CSS class generated by this SASS code:
.p-3 {
padding: 1rem;
}
What will you see on an element with class
p-3?Attempts:
2 left
💡 Hint
Padding adds space inside the element's border.
✗ Incorrect
Padding creates space inside the element, between its content and border, here 1rem on all sides.
❓ accessibility
expert2:30remaining
How to ensure spacing utilities do not harm accessibility?
When generating spacing utilities with SASS, what should you consider to maintain good accessibility?
Attempts:
2 left
💡 Hint
Think about how spacing affects layout and user experience for all users.
✗ Incorrect
Proper spacing improves readability and usability. Overlapping or cramped content can confuse users, especially those using assistive technologies.