Challenge - 5 Problems
Sass Placeholder 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 using placeholder selectors?
Given the Sass code below, what CSS will be generated after compilation?
SASS
%button-style {
padding: 1rem;
border-radius: 0.5rem;
background-color: blue;
color: white;
}
.btn-primary {
@extend %button-style;
font-weight: bold;
}
.btn-secondary {
@extend %button-style;
background-color: gray;
}Attempts:
2 left
💡 Hint
Remember that @extend merges selectors sharing the placeholder styles.
✗ Incorrect
The placeholder selector %button-style is not output directly. Instead, its styles are merged into selectors that extend it. Both .btn-primary and .btn-secondary share the base styles, so they are grouped together. Then, their unique styles are added separately.
🧠 Conceptual
intermediate1:30remaining
Why use placeholder selectors (%) in Sass instead of regular classes?
Which of the following is the main reason to use placeholder selectors (%) in Sass?
Attempts:
2 left
💡 Hint
Think about how placeholders affect the final CSS output.
✗ Incorrect
Placeholder selectors let you write reusable styles that only appear in the final CSS if they are extended. This helps keep CSS smaller and avoids unused styles.
❓ selector
advanced2:00remaining
What happens if you extend a placeholder selector multiple times in Sass?
Consider this Sass code:
%card {
border: 1px solid black;
padding: 1rem;
}
.card-primary {
@extend %card;
background: white;
}
.card-secondary {
@extend %card;
background: lightgray;
}
What will the compiled CSS selectors look like for the shared styles?
Attempts:
2 left
💡 Hint
Remember placeholders do not appear in the final CSS, only selectors that extend them.
✗ Incorrect
When multiple selectors extend the same placeholder, Sass groups those selectors together for the shared styles. The placeholder itself does not appear in the CSS.
❓ layout
advanced1:30remaining
How can placeholder selectors help reduce CSS duplication in complex layouts?
You have multiple card components with similar padding, border, and shadow styles. Which Sass approach best reduces repeated CSS code?
Attempts:
2 left
💡 Hint
Think about how Sass placeholders help reuse styles without extra CSS selectors.
✗ Incorrect
Using a placeholder selector with shared styles and extending it in each card class avoids repeating the same CSS rules multiple times, keeping the CSS smaller and easier to maintain.
❓ accessibility
expert2:30remaining
How do placeholder selectors (%) in Sass affect accessibility when styling focus states?
You want to create consistent focus styles for buttons using a placeholder selector. Which statement is true about accessibility and placeholder selectors?
Attempts:
2 left
💡 Hint
Think about how shared styles help maintain consistent focus outlines for keyboard users.
✗ Incorrect
Placeholder selectors let you define focus styles once and share them across multiple selectors by extending. This helps keep focus outlines consistent, which is important for keyboard navigation and accessibility.