Which rule changes the text color of p elements with the class "highlight" when hovered over?

Prepare for the Web Development 201 Test. Study with flashcards, multiple-choice questions, and detailed explanations. Get exam-ready!

The selection of the first choice is appropriate because it accurately targets paragraph elements with the class "highlight" specifically when the mouse hovers over them. The selector p.highlight:hover indicates that the rule applies to any

element that has the class "highlight" while the mouse is over it.

This combination allows for precise styling, ensuring that only

elements that meet both conditions—being a paragraph and having the highlight class—will change their text color to green upon hovering. This is an important concept in CSS, as it reinforces the idea of specificity in selectors, allowing for tailored design that enhances user interaction.

The other options provide less precise targeting or are syntactically incorrect. For instance, the second option only applies hover effects to elements with the "highlight" class without specifying that they must be contained within paragraph elements. The third option uses an incorrect syntax with "p:hover > highlight," as it seems to imply a child relationship which does not apply in this context. The fourth option would change the text color of all

elements on hover regardless of their class, not just those with "highlight." Therefore, the first choice remains the most effective for the intended style change.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy