Bird
Raised Fist0
SASSmarkup~20 mins

Extend limitations and gotchas in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sass Extend Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What happens when you try to extend a placeholder selector that does not exist?
Consider the following Sass code:
.button { color: blue; @extend %nonexistent; }
What will happen when you compile this Sass code?
SASS
.button { color: blue; @extend %nonexistent; }
AThe compiler creates an empty selector for %nonexistent and applies styles to .button.
BThe compiler ignores the @extend and compiles the .button class normally.
CThe compiler throws an error because the placeholder %nonexistent does not exist.
DThe compiler duplicates the .button styles without any warning or error.
Attempts:
2 left
💡 Hint
Extending a placeholder that is not defined causes a compilation problem.
📝 Syntax
intermediate
2:00remaining
Which option correctly extends multiple selectors in Sass?
You want to extend both .btn and .link selectors in your Sass code. Which of the following is the correct syntax?
A@extend .btn; @extend .link;
B@extend .btn, .link;
C@extend (.btn, .link);
D@extend .btn .link;
Attempts:
2 left
💡 Hint
Sass supports comma-separated lists in @extend.
❓ rendering
advanced
2:00remaining
What is the output CSS of this Sass code with nested @extend?
Given this Sass code:
%base { color: red; } .alert { @extend %base; font-weight: bold; } .error { @extend .alert; }
What CSS will be generated?
SASS
%base { color: red; } .alert { @extend %base; font-weight: bold; } .error { @extend .alert; }
A.alert, .error { color: red; font-weight: bold; }
B.alert { color: red; font-weight: bold; } .error { font-weight: bold; }
C.alert { color: red; font-weight: bold; } .error { color: red; }
D.alert, .error { color: red; } .alert { font-weight: bold; }
Attempts:
2 left
💡 Hint
Extending a selector that itself extends a placeholder merges styles.
❓ selector
advanced
2:00remaining
Why does extending a class with a pseudo-element sometimes fail?
Consider this Sass code:
.btn::before { content: "*"; } .special { @extend .btn::before; }
What is the main reason this @extend does not work as expected?
SASS
.btn::before { content: "*"; } .special { @extend .btn::before; }
AThe .special class must be nested inside .btn to extend its pseudo-element.
BPseudo-elements cannot have content property in Sass.
CThe syntax for extending pseudo-elements requires escaping the colons.
DSass does not support extending selectors with pseudo-elements like ::before.
Attempts:
2 left
💡 Hint
Extending pseudo-elements is not supported in Sass.
❓ accessibility
expert
3:00remaining
How can improper use of @extend affect accessibility in CSS?
Imagine you use @extend to share styles for focus outlines across buttons and links. What is a potential accessibility risk if @extend merges selectors incorrectly?
AFocus styles might be applied to unintended elements, confusing keyboard users.
BThe CSS file size will increase, slowing down page load and hurting accessibility.
CScreen readers will ignore elements with extended styles, reducing accessibility.
D@extend automatically disables focus outlines, making keyboard navigation impossible.
Attempts:
2 left
💡 Hint
Merging selectors can cause styles to apply broadly beyond intended targets.

Practice

(1/5)
1. What is the main limitation of using @extend in Sass?
easy
A. It merges selectors which can cause unexpected CSS output
B. It duplicates all styles instead of reusing them
C. It only works with ID selectors
D. It cannot be used inside nested rules

Solution

  1. Step 1: Understand what @extend does

    @extend reuses styles by merging selectors in the final CSS output.
  2. Step 2: Identify the limitation

    Merging selectors can cause unexpected combined selectors, leading to unwanted CSS rules.
  3. Final Answer:

    It merges selectors which can cause unexpected CSS output -> Option A
  4. Quick Check:

    @extend merges selectors = A [OK]
Hint: Remember: @extend merges selectors, not duplicates styles [OK]
Common Mistakes:
  • Thinking @extend duplicates styles
  • Believing @extend only works with IDs
  • Assuming @extend cannot be nested
2. Which of the following is the correct syntax to extend a placeholder selector %button-base inside a class .primary-button?
easy
A. .primary-button { @extend button-base; }
B. .primary-button { @extend %button-base; }
C. .primary-button { extend %button-base; }
D. .primary-button { @extend #button-base; }

Solution

  1. Step 1: Recall placeholder selector syntax

    Placeholder selectors start with % and must be referenced exactly with @extend %name.
  2. Step 2: Check each option

    Only .primary-button { @extend %button-base; } uses @extend %button-base correctly.
  3. Final Answer:

    .primary-button { @extend %button-base; } -> Option B
  4. Quick Check:

    Use @extend %placeholder syntax = C [OK]
Hint: Always prefix placeholder selectors with % when extending [OK]
Common Mistakes:
  • Omitting the % in the extend statement
  • Using wrong keywords like 'extend' without @
  • Confusing ID (#) with placeholder (%) selectors
3. Given the Sass code:
.alert { color: red; }
.error { @extend .alert; font-weight: bold; }

What will be the compiled CSS output?
medium
A. .alert, .error { color: red; } .error { font-weight: bold; }
B. .alert { color: red; } .error { font-weight: bold; }
C. .error { color: red; font-weight: bold; }
D. .alert { color: red; font-weight: bold; } .error { }

Solution

  1. Step 1: Understand @extend merges selectors

    The .error selector extends .alert, so both selectors share the color: red; style.
  2. Step 2: Check the output structure

    The merged selector .alert, .error has color: red;, and .error has its own font-weight: bold;.
  3. Final Answer:

    .alert, .error { color: red; } .error { font-weight: bold; } -> Option A
  4. Quick Check:

    Selectors merged, styles combined = D [OK]
Hint: Extended selectors share styles in a combined selector list [OK]
Common Mistakes:
  • Expecting duplicated styles instead of merged selectors
  • Thinking extended styles appear only inside the extending selector
  • Ignoring that @extend merges selectors
4. Consider this Sass code:
.btn { color: blue; }
.special-btn { @extend .btn; background: yellow; }
.btn-primary { @extend .btn; }

Why might the compiled CSS include unexpected selectors combined with .btn-primary?
medium
A. Because @extend duplicates styles instead of merging
B. Because @extend only works with placeholder selectors
C. Because @extend merges all selectors that extend .btn into one group
D. Because @extend cannot be used with classes

Solution

  1. Step 1: Understand how @extend merges selectors

    All selectors extending .btn are merged into one combined selector group in the output CSS.
  2. Step 2: Identify why unexpected combinations happen

    Since both .special-btn and .btn-primary extend .btn, their selectors get merged, causing combined selectors.
  3. Final Answer:

    Because @extend merges all selectors that extend .btn into one group -> Option C
  4. Quick Check:

    @extend merges selectors = B [OK]
Hint: Multiple extends on one selector merge all selectors together [OK]
Common Mistakes:
  • Thinking @extend duplicates styles
  • Believing @extend only works with placeholders
  • Assuming @extend cannot be used with classes
5. You want to reuse styles but avoid unwanted CSS output from @extend. Which approach is best?
hard
A. Use @extend inside media queries only
B. Use @extend on regular classes only
C. Duplicate styles manually instead of using @extend
D. Use placeholder selectors (e.g., %base-style) and extend them

Solution

  1. Step 1: Understand placeholder selectors

    Placeholder selectors start with % and do not output CSS unless extended.
  2. Step 2: Why use placeholders with @extend

    Extending placeholders avoids unwanted CSS output because placeholders themselves don't generate CSS.
  3. Step 3: Evaluate other options

    Extending regular classes merges selectors and outputs all styles, duplicating styles is inefficient, and limiting @extend to media queries doesn't solve unwanted output.
  4. Final Answer:

    Use placeholder selectors (e.g., %base-style) and extend them -> Option D
  5. Quick Check:

    Placeholders prevent unwanted CSS output = A [OK]
Hint: Use %placeholders with @extend to avoid extra CSS [OK]
Common Mistakes:
  • Extending regular classes causing large CSS output
  • Copy-pasting styles instead of reusing
  • Misusing @extend inside media queries
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard