Challenge - 5 Problems
Component Variant 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, what CSS will it generate?
$colors: (primary: #0055ff, secondary: #ff5500);
.button {
@each $name, $color in $colors {
&--#{$name} {
background-color: $color;
}
}
}SASS
$colors: (primary: #0055ff, secondary: #ff5500); .button { @each $name, $color in $colors { &--#{$name} { background-color: $color; } } }
Attempts:
2 left
💡 Hint
Remember that & inside a nested block replaces the parent selector.
✗ Incorrect
The & symbol in Sass replaces the parent selector. So &--#{$name} inside .button becomes .button--primary and .button--secondary with their respective background colors.
🧠 Conceptual
intermediate1:30remaining
How does Sass generate multiple component variants efficiently?
Which Sass feature helps generate multiple component variants without repeating code?
Attempts:
2 left
💡 Hint
Think about how Sass can repeat code blocks with different values.
✗ Incorrect
Sass @each loops combined with maps allow you to write one block of code that repeats for each variant, generating multiple CSS classes efficiently.
❓ selector
advanced1:30remaining
Which selector targets only the 'danger' variant button in this Sass code?
Given this Sass snippet:
Which CSS selector will style only the danger variant?
$variants: (primary: blue, danger: red, success: green);
.btn {
@each $name, $color in $variants {
&--#{$name} {
color: $color;
}
}
}Which CSS selector will style only the danger variant?
Attempts:
2 left
💡 Hint
Look at how the variant classes are generated with &--#{$name}.
✗ Incorrect
The Sass code generates classes like .btn--danger. So the selector .btn--danger targets only the danger variant button.
❓ layout
advanced2:00remaining
How to create responsive component variants with Sass and CSS Grid?
You want to create button variants that change layout on small screens using CSS Grid and Sass. Which approach works best?
Attempts:
2 left
💡 Hint
Think about combining Sass nesting with media queries for responsive styles.
✗ Incorrect
Defining grid-template-columns inside media queries nested in each variant block in Sass allows responsive layout changes per variant efficiently.
❓ accessibility
expert2:30remaining
Which Sass-generated variant best supports accessible focus styles?
You have button variants generated by Sass. Which variant style ensures the best keyboard accessibility?
Attempts:
2 left
💡 Hint
Focus styles help keyboard users see which element is active.
✗ Incorrect
Visible outlines on :focus with high contrast help users who navigate with keyboard to identify the focused element, improving accessibility.