Challenge - 5 Problems
Sass @each Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediateWhat is the output CSS of this @each loop?
Given the following Sass code, what CSS will it generate?
SASS
@each $color in red, green, blue { .text-#{$color} { color: $color; } }
Attempts:
2 left
💡 Hint
Remember that @each loops over each item and creates separate blocks.
✗ Incorrect
The @each loop creates a CSS class for each color with the color property set accordingly. Option C shows the correct expanded CSS.
🧠 Conceptual
intermediateHow many CSS classes are generated by this @each loop?
Consider this Sass code:
@each $size in small, medium, large, x-large {
.btn-#{$size} {
font-size: $size;
}
}
How many CSS classes will be generated?
Attempts:
2 left
💡 Hint
Count the number of items in the list after @each.
✗ Incorrect
The list has 4 items, so the loop creates 4 CSS classes, one for each size.
❓ selector
advancedWhich option produces the correct CSS selectors from this @each loop?
Given this Sass code:
@each $icon in home, user, settings {
.icon-#{$icon}::before {
content: "\f#{$icon}";
}
}
Which CSS selectors are generated?
Attempts:
2 left
💡 Hint
Look carefully at the pseudo-element used and the interpolation.
✗ Incorrect
The loop creates selectors with ::before pseudo-elements and interpolates the icon names correctly. Option A matches this.
❓ layout
advancedWhat visual layout results from this Sass @each loop with Flexbox?
This Sass code generates CSS for colored boxes:
$colors: red, green, blue;
.container {
display: flex;
}
@each $color in $colors {
.box-#{$color} {
background-color: $color;
width: 5rem;
height: 5rem;
margin: 0.5rem;
}
}
What will you see in the browser?
Attempts:
2 left
💡 Hint
Flexbox arranges children in a row by default.
✗ Incorrect
The container uses flex display, so the boxes appear side by side horizontally with margin spacing. Each box has a distinct background color and fixed size.
❓ accessibility
expertWhich option correctly uses @each loop to generate accessible button styles with ARIA roles?
You want to create buttons with different themes and ensure each button has an ARIA role for accessibility. Which Sass code correctly generates buttons with roles and styles?
Attempts:
2 left
💡 Hint
ARIA roles are HTML attributes, not CSS properties. Use attribute selectors in CSS.
✗ Incorrect
Option A correctly uses attribute selector to style buttons with role="button" and applies background color and cursor style. Options A and D incorrectly try to set role or aria-role as CSS properties. Option A nests attribute selector inside class but does not apply styles correctly.
