Bird
Raised Fist0
SASSmarkup~20 mins

State class generation (hover, active, disabled) in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
State Class 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 snippet?
Given this SASS code, what CSS does it generate?
.btn {
  background: blue;
  &:hover {
    background: green;
  }
  &.disabled {
    background: gray;
  }
}
SASS
.btn {
  background: blue;
  &:hover {
    background: green;
  }
  &.disabled {
    background: gray;
  }
}
A
.btn { background: blue; }
.btn:hover { background: gray; }
.btn.disabled { background: green; }
B
.btn { background: blue; }
.btn:hover { background: green; }
.btn.disabled { background: gray; }
C
.btn { background: blue; }
.btn.disabled:hover { background: green; }
D
.btn { background: blue; }
.btn:hover.disabled { background: gray; }
Attempts:
2 left
💡 Hint
Look at how the & symbol combines with pseudo-classes and classes.
🧠 Conceptual
intermediate
1:30remaining
Which selector targets the active state in SASS?
You want to style a button when it is being clicked (active state). Which SASS nested selector correctly targets this state?
SASS
.btn {
  // your code here
}
A&:active { background: red; }
B&.active { background: red; }
C&.disabled { background: red; }
D&:hover { background: red; }
Attempts:
2 left
💡 Hint
Active state is a pseudo-class triggered when clicking.
selector
advanced
2:30remaining
What CSS does this SASS produce for combined states?
Consider this SASS code:
.btn {
  color: black;
  &:hover, &:focus {
    color: blue;
  }
  &.disabled {
    color: gray;
    pointer-events: none;
  }
}

What is the correct CSS output?
SASS
.btn {
  color: black;
  &:hover, &:focus {
    color: blue;
  }
  &.disabled {
    color: gray;
    pointer-events: none;
  }
}
A
.btn { color: black; }
.btn:hover:focus { color: blue; }
.btn.disabled { color: gray; pointer-events: none; }
B
.btn { color: black; }
.btn:hover, .disabled:focus { color: blue; }
.btn.disabled { color: gray; pointer-events: none; }
C
.btn { color: black; }
.btn:hover, :focus { color: blue; }
.btn.disabled { color: gray; pointer-events: none; }
D
.btn { color: black; }
.btn:hover, .btn:focus { color: blue; }
.btn.disabled { color: gray; pointer-events: none; }
Attempts:
2 left
💡 Hint
Check how multiple selectors separated by commas are expanded with &.
layout
advanced
1:30remaining
How to disable pointer events for a disabled button in SASS?
You want to make a button unclickable and visually disabled using SASS. Which nested rule correctly disables pointer events and changes opacity?
SASS
.btn {
  background: green;
  color: white;
  &.disabled {
    // your code here
  }
}
A
opacity: 1;
pointer-events: auto;
B
opacity: 0.5;
pointer-events: auto;
C
opacity: 0.5;
pointer-events: none;
D
opacity: 1;
pointer-events: none;
Attempts:
2 left
💡 Hint
Disabled means less visible and no mouse interaction.
accessibility
expert
3:00remaining
Which approach improves accessibility for disabled buttons?
You have a button styled with a .disabled class in SASS. Which additional attribute or practice improves accessibility for keyboard and screen reader users?
SASS
.btn.disabled {
  opacity: 0.5;
  pointer-events: none;
}
AAdd aria-disabled="true" attribute and tabindex="-1" to the button element.
BAdd role="button" attribute only.
CAdd tabindex="0" to make it focusable.
DRemove the button element and replace with a div.
Attempts:
2 left
💡 Hint
Disabled elements should not be focusable and should announce their state.

Practice

(1/5)
1. What is the main purpose of using state classes like :hover, :active, and .disabled in Sass?
easy
A. To change the appearance of elements based on user interaction or status
B. To add animations to elements automatically
C. To create new HTML elements dynamically
D. To load external CSS files conditionally

Solution

  1. Step 1: Understand state classes

    State classes like :hover and :active change how elements look when users interact with them.
  2. Step 2: Identify their purpose

    They help show different styles for hover, active, or disabled states to improve user experience.
  3. Final Answer:

    To change the appearance of elements based on user interaction or status -> Option A
  4. Quick Check:

    State classes change look on interaction [OK]
Hint: State classes show style changes on user actions [OK]
Common Mistakes:
  • Thinking state classes create new elements
  • Confusing state classes with animations
  • Believing state classes load files
2. Which of the following is the correct Sass syntax to create a mixin for hover and active states?
easy
A. @mixin states { :hover { color: blue; } :active { color: red; } }
B. @mixin states { &:hover { color: blue; } &:active { color: red; } }
C. @mixin states { .hover { color: blue; } .active { color: red; } }
D. @mixin states { hover { color: blue; } active { color: red; } }

Solution

  1. Step 1: Review Sass mixin syntax

    Mixins use @mixin name { ... } and nested selectors use &:state for pseudo-classes.
  2. Step 2: Check correct pseudo-class usage

    Correct syntax uses &:hover and &:active inside the mixin.
  3. Final Answer:

    @mixin states { &:hover { color: blue; } &:active { color: red; } } -> Option B
  4. Quick Check:

    Use & with :hover and :active in mixins [OK]
Hint: Use & before pseudo-classes inside mixins [OK]
Common Mistakes:
  • Omitting & before pseudo-classes
  • Using class selectors instead of pseudo-classes
  • Missing @mixin keyword
3. Given this Sass code, what color will the button text be when hovered?
@mixin states {
  &:hover { color: green; }
  &:active { color: orange; }
  &.disabled { color: gray; cursor: not-allowed; }
}

.button {
  color: black;
  @include states;
}
medium
A. Green
B. Black
C. Orange
D. Gray

Solution

  1. Step 1: Understand the mixin states

    The mixin sets color: green on :hover, color: orange on :active, and gray with disabled class.
  2. Step 2: Check the hover state

    When the button is hovered, the :hover style applies, changing text color to green.
  3. Final Answer:

    Green -> Option A
  4. Quick Check:

    Hover changes color to green [OK]
Hint: Hover state color overrides base color [OK]
Common Mistakes:
  • Confusing active color with hover color
  • Ignoring the disabled class
  • Assuming base color stays on hover
4. Identify the error in this Sass code that tries to create disabled state styles:
@mixin states {
  &:hover { color: blue; }
  &:active { color: red; }
  &:disabled { color: gray; cursor: not-allowed; }
}

.button {
  @include states;
}
medium
A. Cannot use mixins inside class selectors
B. Missing semicolon after color: red
C. Using &:disabled instead of &.disabled for disabled class
D. Mixin name should be capitalized

Solution

  1. Step 1: Check pseudo-class vs class usage

    :disabled is a pseudo-class for form elements, but here disabled is a class, so &.disabled is correct.
  2. Step 2: Verify other syntax

    Semicolons are present, mixin naming is flexible, and mixins can be used inside classes.
  3. Final Answer:

    Using &:disabled instead of &.disabled for disabled class -> Option C
  4. Quick Check:

    Use .disabled class selector, not :disabled pseudo-class [OK]
Hint: Use .disabled class, not :disabled pseudo-class [OK]
Common Mistakes:
  • Confusing :disabled pseudo-class with .disabled class
  • Forgetting semicolons
  • Thinking mixins need capital letters
5. You want to create a reusable Sass mixin that adds hover, active, and disabled states to any button. The disabled state should make the button look faded and prevent clicks. Which of these mixins correctly implements this behavior?
hard
A. @mixin button-states { &:hover { background-color: lightblue; } &:active { background-color: blue; } &.disabled { opacity: 1; pointer-events: auto; cursor: not-allowed; } }
B. @mixin button-states { &:hover { background-color: lightblue; } &:active { background-color: blue; } &:disabled { opacity: 0.5; pointer-events: none; cursor: not-allowed; } }
C. @mixin button-states { &:hover { background-color: lightblue; } &:active { background-color: blue; } &.disabled { opacity: 0.5; cursor: default; } }
D. @mixin button-states { &:hover { background-color: lightblue; } &:active { background-color: blue; } &.disabled { opacity: 0.5; pointer-events: none; cursor: not-allowed; } }

Solution

  1. Step 1: Check disabled state styling

    The disabled state should fade the button with opacity: 0.5 and prevent clicks using pointer-events: none.
  2. Step 2: Verify cursor and selector usage

    Using &.disabled is correct for a class. Cursor should be not-allowed to show disabled status.
  3. Step 3: Compare options

    @mixin button-states { &:hover { background-color: lightblue; } &:active { background-color: blue; } &.disabled { opacity: 0.5; pointer-events: none; cursor: not-allowed; } } correctly uses &.disabled, sets opacity to 0.5, disables pointer events, and sets cursor properly.
  4. Final Answer:

    @mixin button-states { &:hover { background-color: lightblue; } &:active { background-color: blue; } &.disabled { opacity: 0.5; pointer-events: none; cursor: not-allowed; } } -> Option D
  5. Quick Check:

    Disabled state fades and disables clicks with pointer-events none [OK]
Hint: Use pointer-events:none and opacity for disabled state [OK]
Common Mistakes:
  • Using :disabled pseudo-class instead of .disabled class
  • Not disabling pointer events on disabled
  • Setting opacity to 1 in disabled state