0
0
SASSmarkup~20 mins

Component variant generation in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Component Variant 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, 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;
    }
  }
}
A
.button--primary {
  background-color: #0055ff;
}
.button--secondary {
  background-color: #ff5500;
}
B
.button {
  &--primary {
    background-color: #0055ff;
  }
  &--secondary {
    background-color: #ff5500;
  }
}
C
.button--primary {
  background-color: #0055ff;
}
.button {
  &--secondary {
    background-color: #ff5500;
  }
}
D
.button--primary {
  background-color: #0055ff;
}
.button--secondary {
  background-color: #0055ff;
}
Attempts:
2 left
💡 Hint
Remember that & inside a nested block replaces the parent selector.
🧠 Conceptual
intermediate
1:30remaining
How does Sass generate multiple component variants efficiently?
Which Sass feature helps generate multiple component variants without repeating code?
AWriting separate CSS classes manually for each variant
BUsing JavaScript to dynamically add classes at runtime
CUsing @each loops with maps to iterate over variant names and styles
DUsing inline styles directly in HTML elements
Attempts:
2 left
💡 Hint
Think about how Sass can repeat code blocks with different values.
selector
advanced
1:30remaining
Which selector targets only the 'danger' variant button in this Sass code?
Given this Sass snippet:
$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?
A.btn .danger
B.btn--danger
C.btn-danger
D.btn--danger:hover
Attempts:
2 left
💡 Hint
Look at how the variant classes are generated with &--#{$name}.
layout
advanced
2: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?
ADefine grid-template-columns inside a media query within each variant block in Sass
BUse inline styles on buttons to change grid layout dynamically
CWrite separate CSS files for each screen size variant
DUse JavaScript to toggle grid classes on window resize
Attempts:
2 left
💡 Hint
Think about combining Sass nesting with media queries for responsive styles.
accessibility
expert
2: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?
AVariant that changes background color on :hover only
BVariant that removes all outlines and shadows on :focus
CVariant that uses opacity change on :active without focus styles
DVariant with a visible outline on :focus using a high-contrast color
Attempts:
2 left
💡 Hint
Focus styles help keyboard users see which element is active.