Challenge - 5 Problems
Hover State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2: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? */Attempts:
2 left
💡 Hint
Hover means when the mouse pointer is over the element.
✗ Incorrect
The :hover pseudo-class applies styles when the mouse is over the element. :focus applies when the element is focused by keyboard or mouse. .active is a class, not a state. ::hover is invalid syntax.
❓ rendering
intermediate2: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;
}Attempts:
2 left
💡 Hint
Hover styles override normal styles when mouse is over the button.
✗ Incorrect
The :hover style changes background to #ff6347 and text color to white only when hovered. Otherwise, normal styles apply.
❓ layout
advanced2:00remaining
Why does the hover effect trigger on child elements?
Consider this HTML and CSS:
HTML:
CSS:
.card:hover {
background-color: yellow;
}
Why does hovering over the
Text inside card
text inside the card change the card's background color?
Attempts:
2 left
💡 Hint
Hover applies when mouse is over the element or its visible area.
✗ Incorrect
The :hover pseudo-class applies when the mouse is over the element or any of its children. Hovering over
inside .card triggers .card:hover because the child is within the parent's area. A is wrong (children do not block by default), C is false, D selector is valid.
❓ accessibility
advanced2: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;
}Attempts:
2 left
💡 Hint
Keyboard users navigate using focus, not hover.
✗ Incorrect
Keyboard users see focus styles, so matching :focus styles to :hover ensures accessibility. :active is for pressed state, :visited is for links, and !important does not solve accessibility.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Touch devices do not have a mouse pointer but simulate hover in some ways.
✗ Incorrect
On touch devices, tapping an element can trigger :hover styles as a toggle until another tap happens. This helps simulate hover effects without a mouse.