0
0
SASSmarkup~20 mins

BEM naming with SASS nesting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BEM SASS 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 BEM nesting?
Given the following SASS code, what CSS will it produce?
.block {
  &__element {
    color: red;
  }
}
SASS
.block {
  &__element {
    color: red;
  }
}
A
.block__element {
  color: red;
}
B
.block .__element {
  color: red;
}
C
.block__element {
  color: blue;
}
D
.block__element {
  color: red;
  font-weight: bold;
}
Attempts:
2 left
💡 Hint
Remember that & replaces the parent selector exactly in SASS nesting.
selector
intermediate
2:00remaining
Which selector matches the BEM modifier in this SASS snippet?
Look at this SASS code:
.block {
  &--active {
    background: green;
  }
}

Which CSS selector does it generate?
SASS
.block {
  &--active {
    background: green;
  }
}
A
.block--active {
  background: green;
}
B
.block .--active {
  background: green;
}
C
.block--active {
  background: red;
}
D
.block--active.active {
  background: green;
}
Attempts:
2 left
💡 Hint
Modifiers in BEM use double dashes and are appended directly to the block name.
layout
advanced
2:30remaining
How does this nested BEM SASS code affect layout?
Consider this SASS code:
.card {
  display: flex;
  &__header {
    flex: 1;
  }
  &__body {
    flex: 2;
  }
}

What will be the layout behavior of .card__header and .card__body inside .card?
SASS
.card {
  display: flex;
  &__header {
    flex: 1;
  }
  &__body {
    flex: 2;
  }
}
A.card__header takes twice the space of .card__body inside .card.
B.card__header and .card__body stack vertically inside .card.
C.card__header takes one part and .card__body takes two parts of the horizontal space inside .card.
D.card__header and .card__body have no flex behavior inside .card.
Attempts:
2 left
💡 Hint
Flex container distributes space according to flex values of children.
accessibility
advanced
2:30remaining
Which BEM SASS nesting approach improves accessibility for a button with icon?
You want to style a button with an icon inside using BEM and SASS nesting. Which code snippet best supports accessibility by semantic HTML and clear structure?
.button {
  &__icon {
    margin-right: 0.5rem;
  }
}
SASS
.button {
  &__icon {
    margin-right: 0.5rem;
  }
}
AUse <div role="button"> with <i class="button__icon"> for the icon and style with .button__icon.
BUse <button> with <img class="button__icon"> without alt attribute and style with .button__icon.
CUse <a href="#" class="button"> with <svg class="button__icon"> and no aria attributes.
DUse <button> with <span class="button__icon" aria-hidden="true"> for the icon and style with .button__icon.
Attempts:
2 left
💡 Hint
Semantic elements and hiding decorative icons from screen readers help accessibility.
🧠 Conceptual
expert
3:00remaining
What is the main advantage of using BEM naming with SASS nesting in large projects?
Why do developers prefer combining BEM naming conventions with SASS nesting for CSS in big projects?
AIt reduces CSS file size by automatically removing unused styles during compilation.
BIt creates clear, reusable, and maintainable CSS by organizing styles with predictable class names and nested structure.
CIt allows JavaScript to directly manipulate nested SASS variables at runtime for dynamic styling.
DIt forces all styles to be inline, improving page load speed and eliminating external CSS files.
Attempts:
2 left
💡 Hint
Think about how naming and nesting help developers understand and manage styles.