0
0
SASSmarkup~20 mins

Placeholder selectors with % in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Placeholder 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 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;
}
A
.btn-primary {
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: blue;
  color: white;
  font-weight: bold;
}
.btn-secondary {
  background-color: gray;
  color: white;
  padding: 1rem;
  border-radius: 0.5rem;
}
B
.btn-primary {
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: blue;
  color: white;
  font-weight: bold;
}
.btn-secondary {
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: gray;
  color: white;
}
C
.btn-primary, .btn-secondary {
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: blue;
  color: white;
}
.btn-primary {
  font-weight: bold;
}
.btn-secondary {
  background-color: gray;
}
D
.btn-primary, .btn-secondary {
  padding: 1rem;
  border-radius: 0.5rem;
  color: white;
}
.btn-primary {
  background-color: blue;
  font-weight: bold;
}
.btn-secondary {
  background-color: gray;
}
Attempts:
2 left
💡 Hint
Remember that @extend merges selectors sharing the placeholder styles.
🧠 Conceptual
intermediate
1: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?
AThey generate CSS classes that can be styled directly in HTML.
BThey allow sharing styles without generating extra CSS selectors unless extended.
CThey automatically add vendor prefixes to CSS properties.
DThey create JavaScript variables for styling.
Attempts:
2 left
💡 Hint
Think about how placeholders affect the final CSS output.
selector
advanced
2: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?
A
.card-primary, .card-secondary {
  border: 1px solid black;
  padding: 1rem;
}
.card-primary {
  background: white;
}
.card-secondary {
  background: lightgray;
}
B
%card {
  border: 1px solid black;
  padding: 1rem;
}
.card-primary {
  @extend %card;
  background: white;
}
.card-secondary {
  @extend %card;
  background: lightgray;
}
C
.card-primary {
  border: 1px solid black;
  padding: 1rem;
  background: white;
}
.card-secondary {
  border: 1px solid black;
  padding: 1rem;
  background: lightgray;
}
D
.card-primary, .card-secondary, %card {
  border: 1px solid black;
  padding: 1rem;
}
.card-primary {
  background: white;
}
.card-secondary {
  background: lightgray;
}
Attempts:
2 left
💡 Hint
Remember placeholders do not appear in the final CSS, only selectors that extend them.
layout
advanced
1: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?
ACreate separate CSS files for each card and import them.
BWrite the same styles inside each card class separately.
CUse inline styles in HTML for each card component.
DUse a placeholder selector with shared styles and extend it in each card class.
Attempts:
2 left
💡 Hint
Think about how Sass placeholders help reuse styles without extra CSS selectors.
accessibility
expert
2: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?
AUsing placeholder selectors for focus styles ensures all buttons share the same accessible focus outline without extra CSS duplication.
BPlaceholder selectors automatically add ARIA attributes to elements for accessibility.
CPlaceholder selectors cannot style focus states because they do not generate CSS selectors.
DFocus styles must be written inline in HTML for accessibility, so placeholders are irrelevant.
Attempts:
2 left
💡 Hint
Think about how shared styles help maintain consistent focus outlines for keyboard users.