0
0
SASSmarkup~20 mins

Combining & with BEM naming in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BEM & Sass Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
What CSS selector does this Sass code produce?
Given the Sass code below, what is the final CSS selector generated for the .block__element--modifier style?
SASS
.block {
  &__element {
    &--modifier {
      color: red;
    }
  }
}
A.block__element--modifier { color: blue; }
B.block .__element--modifier { color: red; }
C.block__element .--modifier { color: red; }
D.block__element--modifier { color: red; }
Attempts:
2 left
💡 Hint
Remember that & replaces the parent selector exactly where it appears.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in Sass when combining & with BEM naming?
Identify which Sass snippet below will cause a syntax error due to incorrect use of & with BEM naming.
A
.block {
  &--modifier
    color: green;
  }
B
.block {
  &__element--modifier {
    color: red;
  }
}
C
.block {
  &__element {
    color: blue;
  }
}
D
.block {
  &__element--modifier {
    &--extra {
      color: yellow;
    }
  }
}
Attempts:
2 left
💡 Hint
Check for missing opening braces `{` after nested selectors.
selector
intermediate
2:00remaining
Which Sass code produces a descendant selector instead of BEM concatenated class?
Choose the Sass code that compiles to a descendant selector `.block __element` instead of the proper BEM concatenated `.block__element`.
A
.block {
  & __element {
    color: yellow;
  }
}
B
.block {
  &--modifier {
    color: green;
  }
}
C
.block {
  &__element {
    color: blue;
  }
}
D
.block {
  &__element--modifier {
    color: red;
  }
}
Attempts:
2 left
💡 Hint
A space after & inserts a descendant combinator (space), preventing concatenation for BEM class names.
rendering
advanced
2:00remaining
What color will the element with class block__element--modifier have?
Given the Sass code below, what color will the element with class block__element--modifier display in the browser?
SASS
.block {
  &__element {
    color: blue;
    &--modifier {
      color: red;
    }
  }
}
ABlue
BNo color applied
CRed
DPurple
Attempts:
2 left
💡 Hint
Look at the nested selectors and which color applies to the modifier class.
accessibility
expert
3:00remaining
How to improve accessibility when using BEM modifiers with & in Sass?
You have a button styled with BEM naming and Sass using & for modifiers. Which practice improves accessibility the most?
AUse only BEM modifiers with & in Sass to change colors for visual states.
BAdd ARIA roles and states to the button element in HTML, not just rely on CSS classes.
CAdd tabindex="-1" to all modifier classes to prevent keyboard focus.
DUse !important in Sass modifiers to ensure styles override defaults.
Attempts:
2 left
💡 Hint
Think about what helps screen readers and keyboard users, not just visual styles.