0
0
SASSmarkup~20 mins

Spacing utility generation in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spacing Utility Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2: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);
A.m-2 { margin: 2rem; }
B.m-2 { margin: 0.5rem; }
C.m-2 { padding: 0.5rem; }
D.m-2 { margin: 0.25rem; }
Attempts:
2 left
💡 Hint
Look at how the mixin uses the $property and $sizes map to create classes.
🧠 Conceptual
intermediate
1: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?
AUsing @import to include external files
BUsing @if conditional statements
CUsing @extend to inherit styles
DUsing @each loop with a map of sizes
Attempts:
2 left
💡 Hint
Think about repeating code for multiple values.
selector
advanced
1: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?
A.p-small
B.padding-small
C.p_small
D.p-small-value
Attempts:
2 left
💡 Hint
Look at how the class name is constructed using interpolation.
layout
advanced
1: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?
AThe element's font size will increase by 1rem.
BThe element will have 1rem margin outside its border, pushing other elements away.
CThe element will have 1rem padding on all sides, creating space inside the element's border.
DThe element will have a 1rem border thickness.
Attempts:
2 left
💡 Hint
Padding adds space inside the element's border.
accessibility
expert
2:30remaining
How to ensure spacing utilities do not harm accessibility?
When generating spacing utilities with SASS, what should you consider to maintain good accessibility?
AEnsure spacing does not cause content overlap or reduce readable area, and test with keyboard navigation and screen readers.
BUse only fixed pixel values for spacing to keep layout consistent.
CAvoid using spacing utilities on interactive elements to prevent confusion.
DOnly apply spacing utilities on elements with aria-label attributes.
Attempts:
2 left
💡 Hint
Think about how spacing affects layout and user experience for all users.