Bird
Raised Fist0
SASSmarkup~20 mins

Avoiding over-nesting in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Nesting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate
2:00remaining
What is the output CSS selector?
Given this Sass code, what is the compiled CSS selector for the .button hover state?
SASS
$color: blue;
.button {
  color: $color;
  &:hover {
    color: darken($color, 10%);
  }
}
A.button:hover { color: #00008b; }
B.button .hover { color: #00008b; }
C.button:hover { color: darken(blue, 10%); }
D.button:hover { color: blue; }
Attempts:
2 left
💡 Hint
Remember that &:hover appends :hover to the parent selector.
❓ layout
intermediate
2:00remaining
How many CSS rules are generated?
Consider this Sass code avoiding over-nesting. How many CSS rules will be generated?
SASS
.nav {
  display: flex;
  .item {
    padding: 1rem;
  }
  &.active {
    background: green;
  }
}
A2
B4
C3
D1
Attempts:
2 left
💡 Hint
Count each unique selector generated after nesting.
🧠 Conceptual
advanced
2:00remaining
Why avoid deep nesting in Sass?
What is the main reason to avoid deep nesting in Sass stylesheets?
ADeep nesting improves browser rendering speed.
BDeep nesting reduces the file size of the compiled CSS.
CDeep nesting automatically fixes accessibility issues.
DDeep nesting makes CSS selectors too specific and hard to override.
Attempts:
2 left
💡 Hint
Think about how CSS specificity affects styling and maintenance.
📝 Syntax
advanced
2:00remaining
Which Sass code avoids over-nesting?
Choose the Sass code snippet that avoids over-nesting while styling a card component with a title and description.
A
.card {
  .title {
    font-weight: bold;
    .description {
      color: gray;
    }
  }
}
B
.card {
  .title {
    font-weight: bold;
  }
  .description {
    color: gray;
  }
}
C
.card {
  & .title {
    font-weight: bold;
    & .description {
      color: gray;
    }
  }
}
D
.card {
  .title {
    font-weight: bold;
  }
}
.card .description {
  color: gray;
}
Attempts:
2 left
💡 Hint
Avoid nesting selectors inside each other more than one level deep.
❓ accessibility
expert
3:00remaining
How does over-nesting affect accessibility?
Which statement best explains how over-nesting in Sass can indirectly impact web accessibility?
AOver-nesting can cause overly specific selectors that make it hard to update focus styles, reducing keyboard navigation clarity.
BOver-nesting automatically disables screen readers on nested elements.
COver-nesting improves color contrast by grouping styles tightly.
DOver-nesting adds ARIA labels to nested elements by default.
Attempts:
2 left
💡 Hint
Think about how CSS specificity affects style overrides for accessibility features.

Practice

(1/5)
1. Why is it recommended to avoid nesting more than 2 levels deep in Sass?
easy
A. Because Sass does not support nesting beyond 2 levels
B. Because deep nesting makes CSS harder to read and slower to load
C. Because deep nesting automatically breaks the styles
D. Because browsers ignore styles nested more than 2 levels

Solution

  1. Step 1: Understand the impact of deep nesting

    Deep nesting creates very specific selectors that are hard to read and maintain.
  2. Step 2: Consider browser performance

    Browsers take longer to match deeply nested selectors, slowing page rendering.
  3. Final Answer:

    Because deep nesting makes CSS harder to read and slower to load -> Option B
  4. Quick Check:

    Deep nesting = Hard to read and slow [OK]
Hint: Keep nesting shallow to improve readability and speed [OK]
Common Mistakes:
  • Thinking Sass limits nesting levels
  • Believing browsers ignore deep nesting
  • Assuming deep nesting breaks styles
2. Which of the following Sass snippets correctly avoids over-nesting?
easy
A. .menu { color: blue; .item { font-size: 1rem; } }
B. .menu { .item { .link { color: red; } } }
C. .menu { .item { .link { .icon { width: 10px; } } } }
D. .menu { .item { .link { .icon { .badge { display: none; } } } } }

Solution

  1. Step 1: Count nesting levels in each snippet

    .menu { color: blue; .item { font-size: 1rem; } } nests 1 level inside .menu, which is acceptable. Options B, C, and D nest 2, 3, and 4 levels respectively.
  2. Step 2: Recall the rule to avoid nesting beyond 2 levels

    Only .menu { color: blue; .item { font-size: 1rem; } } stays within 2 levels of nesting, avoiding over-nesting.
  3. Final Answer:

    .menu { color: blue; .item { font-size: 1rem; } } -> Option A
  4. Quick Check:

    Max 2 levels nesting = .menu { color: blue; .item { font-size: 1rem; } } [OK]
Hint: Count curly braces to check nesting depth [OK]
Common Mistakes:
  • Confusing 2 levels with 3 or more
  • Ignoring nesting inside nested selectors
  • Assuming deep nesting is always fine
3. What CSS will be generated by this Sass code avoiding over-nesting?
.card {
  background: white;
  .title {
    font-weight: bold;
  }
}
medium
A. .card { background: white; } .card .title { font-weight: bold; }
B. .card .title { background: white; font-weight: bold; }
C. .card { background: white; font-weight: bold; } .title { font-weight: bold; }
D. .title { font-weight: bold; }

Solution

  1. Step 1: Understand Sass nesting output

    The nested .title inside .card becomes a selector combining both: .card .title.
  2. Step 2: Translate Sass to CSS selectors

    .card styles apply to .card, and .card .title styles apply to .title inside .card.
  3. Final Answer:

    .card { background: white; } .card .title { font-weight: bold; } -> Option A
  4. Quick Check:

    Nesting creates combined selectors = .card { background: white; } .card .title { font-weight: bold; } [OK]
Hint: Nested selectors become combined in CSS [OK]
Common Mistakes:
  • Merging styles incorrectly into one selector
  • Dropping parent selector in nested styles
  • Assuming nested styles apply globally
4. Identify the problem in this Sass code that tries to avoid over-nesting:
.nav {
  ul {
    li {
      a {
        color: blue;
      }
    }
  }
}
medium
A. It misses a closing brace for .nav
B. It uses invalid Sass syntax for nesting
C. It uses too few nesting levels
D. It nests 4 levels deep, which is too much

Solution

  1. Step 1: Count nesting levels in the code

    .nav > ul > li > a means 4 levels of nesting.
  2. Step 2: Compare with recommended nesting depth

    Recommended max is 2 levels to avoid complexity; 4 is too deep.
  3. Final Answer:

    It nests 4 levels deep, which is too much -> Option D
  4. Quick Check:

    Nesting depth 4 > 2 is problem [OK]
Hint: Count nested selectors to find over-nesting [OK]
Common Mistakes:
  • Thinking 4 levels is acceptable
  • Confusing syntax errors with nesting depth
  • Ignoring closing braces
5. You want to style a button inside a card inside a section, but avoid over-nesting. Which Sass structure is best?
hard
A. .section { .card-button { background: green; } }
B. .section-card-button { background: green; }
C. .section { .card { &-button { background: green; } } }
D. .section { .card { .button { background: green; } } }

Solution

  1. Step 1: Understand over-nesting avoidance

    Deep nesting like in .section { .card { .button { background: green; } } } is discouraged; flat or shallow nesting is better.
  2. Step 2: Analyze .section { .card { &-button { background: green; } } }'s use of &-button

    .section { .card { &-button { background: green; } } } nests only 2 levels and uses the parent selector & to create .card-button, keeping nesting shallow and naming clear.
  3. Step 3: Compare with other options

    .section-card-button { background: green; } flattens all into one class, losing semantic structure. .section { .card-button { background: green; } } nests only 1 level but creates a combined class that may not reflect HTML structure well.
  4. Final Answer:

    .section { .card { &-button { background: green; } } } -> Option C
  5. Quick Check:

    Use & to keep nesting shallow and names clear [OK]
Hint: Use & to create modifiers without deep nesting [OK]
Common Mistakes:
  • Nesting too deep without & usage
  • Flattening all classes losing structure
  • Ignoring semantic class names
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