0
0
CSSmarkup~20 mins

Hover state in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hover State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Identify the correct CSS selector for hover
Which CSS selector correctly changes the background color of a button when you hover over it?
CSS
button {
  background-color: lightblue;
}

/* Which selector below changes background on hover? */
Abutton:hover { background-color: darkblue; }
Bbutton:focus { background-color: darkblue; }
Cbutton.active { background-color: darkblue; }
Dbutton::hover { background-color: darkblue; }
Attempts:
2 left
💡 Hint
Hover means when the mouse pointer is over the element.
rendering
intermediate
2:00remaining
What color does the button show on hover?
Given this CSS, what background color will the button have when hovered?
CSS
button {
  background-color: #f0f0f0;
  color: black;
}
button:hover {
  background-color: #ff6347;
  color: white;
}
ABackground: black, Text: white
BBackground: #ff6347 (tomato red), Text: white
CBackground: white, Text: black
DBackground: #f0f0f0 (light gray), Text: black
Attempts:
2 left
💡 Hint
Hover styles override normal styles when mouse is over the button.
layout
advanced
2:00remaining
Why does the hover effect trigger on child elements?
Consider this HTML and CSS: HTML:

Text inside card

CSS: .card:hover { background-color: yellow; } Why does hovering over the

text inside the card change the card's background color?

ABecause the hover state applies when hovering over the .card element or its children.
BBecause the CSS selector .card:hover is invalid and does not work.
CBecause the <p> element is outside the .card element in the DOM.
DBecause the <p> element blocks pointer events, so hover on .card is not detected.
Attempts:
2 left
💡 Hint
Hover applies when mouse is over the element or its visible area.
accessibility
advanced
2:00remaining
How to make hover effects accessible for keyboard users?
Which CSS approach ensures that keyboard users see the same style changes as mouse users when focusing on a button?
CSS
button {
  background-color: lightgray;
}
button:hover {
  background-color: blue;
  color: white;
}
AAdd button:visited styles matching button:hover styles.
BAdd button:active styles matching button:hover styles.
CAdd button:focus styles matching button:hover styles.
DAdd button:hover styles with !important to override focus.
Attempts:
2 left
💡 Hint
Keyboard users navigate using focus, not hover.
🧠 Conceptual
expert
2:00remaining
What happens if you use :hover on a touch device?
On a smartphone or tablet (touch device), what is the typical behavior of CSS :hover styles?
AHover styles apply automatically when the page loads.
BHover styles never apply because there is no mouse pointer.
CHover styles apply only when the user long-presses the element.
DHover styles apply when the user taps the element, acting like a toggle.
Attempts:
2 left
💡 Hint
Touch devices do not have a mouse pointer but simulate hover in some ways.