0
0
SASSmarkup~20 mins

Parent selector with & in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Parent Selector Master
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 resulting CSS selector for the nested rule?
SASS
.button {
  &-primary {
    color: blue;
  }
}
A.primary-button { color: blue; }
B.button-primary { color: blue; }
C.button .primary { color: blue; }
D.button > .primary { color: blue; }
Attempts:
2 left
💡 Hint
The & symbol represents the parent selector exactly as it is.
selector
intermediate
2:00remaining
Which CSS selector is generated by this Sass snippet?
Look at this Sass code and choose the correct CSS selector it compiles to:
SASS
.nav {
  ul {
    &.active {
      font-weight: bold;
    }
  }
}
A.nav .ul.active { font-weight: bold; }
B.nav ul .active { font-weight: bold; }
C.nav ul > .active { font-weight: bold; }
D.nav ul.active { font-weight: bold; }
Attempts:
2 left
💡 Hint
The & replaces the parent selector exactly where it appears.
📝 Syntax
advanced
2:00remaining
What error does this Sass code cause?
Examine this Sass code and select the error it produces when compiled:
SASS
.card {
  &__header {
    color: red
  }
}
ASyntaxError: Missing semicolon after 'color: red'
BNo error, compiles correctly
CRuntimeError: Undefined variable
DSyntaxError: Unexpected token '&'
Attempts:
2 left
💡 Hint
Check punctuation carefully in CSS properties.
rendering
advanced
2:00remaining
What visual style will the button have?
Given this Sass code, what color will the button text be in the browser?
SASS
.btn {
  color: black;
  &--danger {
    color: red;
  }
}
AAll buttons will have black text, including 'btn--danger'.
BThe button with class 'btn--danger' will have black text.
CThe button with class 'btn--danger' will have red text.
DThe button with class 'btn--danger' will have blue text.
Attempts:
2 left
💡 Hint
Look at how the nested selector changes the class name and color.
accessibility
expert
3:00remaining
How does using & in Sass help maintain accessibility in CSS?
Choose the best explanation of how the parent selector & can improve accessibility in CSS code:
AIt helps create clear, consistent class names that assist screen readers in identifying elements.
BIt automatically adds ARIA attributes to elements for better accessibility.
CIt prevents keyboard navigation by nesting selectors deeply.
DIt disables color contrast checks in CSS.
Attempts:
2 left
💡 Hint
Think about how naming conventions affect accessibility tools.