WEB-DEVELOPMENT-FOUNDATION practice question 3 of 15

What is matched by the :hover selector?

Full set: 75 questions
Answer options
A: Any element that has no children
B: Any element text that is indicated by the user
C: Any element that the cursor is on Correct answer
D: Any element that is user-editable
Correct Answer:
C. Any element that the cursor is on
Explanation

The :hover pseudo-class in CSS is a user action pseudo-class that applies styles to an element when a user interacts with it using a pointing device, but does not necessarily activate it. This state is most commonly triggered when the user's cursor (mouse pointer) is positioned over the element. It is used to provide visual feedback to the user, indicating that the element is interactive.

Why Incorrect

A. Any element that has no children: This is incorrect. This condition is matched by the :empty pseudo-class, not :hover.
B. Any element text that is indicated by the user: This is incorrect. This describes the ::selection pseudo-element, which styles the portion of a document highlighted by the user.
D. Any element that is user-editable: This is incorrect. This describes elements with the contenteditable attribute or enabled form inputs, which are not specifically targeted by :hover.

References

1. Mozilla Developer Network (MDN) Web Docs: In the documentation for CSS Pseudo-classes, :hover is defined as matching "when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer)."

Source: MDN Web Docs, ":hover", retrieved from https://developer.mozilla.org/en-US/docs/Web/CSS/:hover

2. W3C (World Wide Web Consortium) Specification: The official CSS Selectors Level 4 specification defines :hover under the "User Action Pseudo-classes" section. It states, "The :hover pseudo-class applies while the user designates an element with a pointing device, but does not activate it."

Source: W3C, "Selectors Level 4", Section 8.3. User Action Pseudo-classes: :hover, :active, :focus, retrieved from https://www.w3.org/TR/selectors-4/#hover-pseudo

3. MIT OpenCourseWare: In the course materials for "6.170 Software Studio," CSS selectors are explained. The :hover selector is consistently described as applying styles when the mouse cursor is over an element, which aligns with the correct answer.

Source: MIT OpenCourseWare, "6.170 Software Studio, Lecture 5: HTML & CSS", Section on CSS Selectors.

Scroll to Top