Which of the following rules styles the first paragraph in each div?

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

The option that correctly styles the first paragraph in each div is the one that uses the :first-child pseudo-class on the paragraph element. This syntax specifically targets the first child paragraph element within a div, applying the blue color styling only to that first paragraph.

When you use "div p:first-child," the rule matches any paragraph element that is the very first child of its parent div. This means that if a div contains one or more paragraphs, only the first paragraph will receive the blue color styling, regardless of how many paragraphs come after it.

Other choices do not achieve the same result. For instance, "div p" styles all paragraphs within all divs, not just the first one. The "div > p" selector targets direct child paragraphs of div elements, but it also doesn't limit itself to only the first child. The "div:first-child p" syntax would select paragraphs within divs that are the first child of a parent element, which may not target the first paragraph within each div specifically. Thus, the chosen rule is the one that most accurately applies the desired style to just the first paragraph inside each div.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy