A placeholder selector in Sass is a special selector that starts with %. It is not rendered directly in the CSS but can be extended by other selectors to share styles.
Click to reveal answer
beginner
How do you define a placeholder selector in Sass?
You define a placeholder selector by starting the selector name with %, for example: %button-style { color: blue; }.
Click to reveal answer
intermediate
What is the main benefit of using placeholder selectors with % in Sass?
They help avoid repeating CSS code by allowing multiple selectors to share the same styles without generating extra CSS for the placeholder itself.
Click to reveal answer
beginner
How do you use a placeholder selector in another selector?
You use the @extend directive to include the styles from a placeholder selector. For example: .btn {@extend %button-style;}.
Click to reveal answer
intermediate
What happens if you define a placeholder selector but never extend it?
No CSS is generated for that placeholder selector because it only outputs styles when extended by other selectors.
Click to reveal answer
What symbol starts a placeholder selector in Sass?
A%
B#
C.
D&
✗ Incorrect
Placeholder selectors always start with the percent sign % in Sass.
Which Sass directive is used to apply styles from a placeholder selector?
A@extend
B@include
C@mixin
D@import
✗ Incorrect
The @extend directive is used to inherit styles from a placeholder selector.
If a placeholder selector is not extended, what CSS is generated?
AThe placeholder styles are output as a class selector
BAn error occurs
CNo CSS is generated
DCSS with the placeholder selector name
✗ Incorrect
Placeholder selectors only generate CSS when extended; otherwise, no CSS is output.
Which of these is a valid placeholder selector?
A.nav-item
B%nav-item
C#nav-item
D&nav-item
✗ Incorrect
Placeholder selectors start with %, so %nav-item is valid.
Why use placeholder selectors instead of regular classes?
ATo style HTML elements directly
BTo make styles inline
CTo add JavaScript behavior
DTo create reusable styles without extra CSS output
✗ Incorrect
Placeholder selectors help reuse styles without generating extra CSS selectors.
Explain how placeholder selectors with % work in Sass and why they are useful.
Think about sharing styles without extra CSS code.
You got /4 concepts.
Describe the difference between a placeholder selector and a regular class selector in Sass.
Focus on CSS output and reuse.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a placeholder selector in Sass, which starts with %?
easy
A. To hold reusable styles that can be extended by other selectors
B. To create a new HTML element
C. To define a variable for colors
D. To write comments in Sass code
Solution
Step 1: Understand what placeholder selectors do
Placeholder selectors start with % and are used to hold styles that are not output directly but can be reused.
Step 2: Identify their usage
They are extended by other selectors using @extend to apply the stored styles without duplicating CSS.
Final Answer:
To hold reusable styles that can be extended by other selectors -> Option A
Quick Check:
Placeholder selectors = reusable styles [OK]
Hint: Remember % means reusable style block [OK]
Common Mistakes:
Thinking % creates HTML elements
Confusing % with variables
Using % for comments
2. Which of the following is the correct syntax to extend a placeholder selector named %button-style inside a Sass rule?
easy
A. button { @include %button-style; }
B. button { extend %button-style; }
C. button { @extend %button-style; }
D. button { %button-style; }
Solution
Step 1: Recall the syntax for extending placeholders
In Sass, to apply styles from a placeholder, you use @extend %placeholder-name; inside a selector.
Step 2: Check each option
button { @extend %button-style; } uses @extend %button-style; correctly. The other options use incorrect keywords or syntax.
D. Border property should be inside .card, not %card-style
Solution
Step 1: Check the syntax of @extend
The correct syntax requires the @ symbol before extend to work properly.
Step 2: Identify the error in the code
The code uses extend %card-style; without @, causing a syntax error.
Final Answer:
Missing @ symbol before extend -> Option B
Quick Check:
@extend must have @ symbol [OK]
Hint: Always use @ before extend keyword [OK]
Common Mistakes:
Omitting @ before extend
Misnaming placeholder selectors
Misplacing properties inside placeholders
5. You want to create two button styles, .primary-btn and .secondary-btn, sharing common styles but with different colors. Which Sass code correctly uses placeholder selectors to avoid repeating common styles?