The first <p> with text 'First' is a direct child of <div>.
Step 2: Check nested <p> inside <section>
The second <p> with text 'Second' is inside <section>, which is a child of <div>, so it is a grandchild, not direct child.
Final Answer:
Only 'First' paragraph -> Option C
Quick Check:
Child selector affects direct children only [OK]
Hint: Only immediate children match > selector, nested deeper do not [OK]
Common Mistakes:
Assuming all nested elements are selected
Ignoring the nesting inside <section>
Confusing descendant selector with child selector
4. This CSS code is intended to color only direct <li> children of <ol> blue:
ol > li { color: blue }
But it colors all <li> elements inside nested <ol> too. What is the problem?
medium
A. CSS does not support child selectors
B. The selector should be ol li instead
C. Missing semicolon after color property
D. Nested <ol> inside <li> causes deeper <li> to be direct children of inner ol
Solution
Step 1: Understand nested lists structure
Nested <ol> inside <li> creates new direct children <li> for the inner ol.
Step 2: Explain why all <li> get colored
The selector ol > li matches direct children of any ol, including nested ones, so all nested li get colored.
Final Answer:
Nested <ol> inside <li> causes deeper <li> to be direct children of inner ol -> Option D
Quick Check:
Child selector matches direct children of each ol, including nested [OK]
Hint: Nested ol creates new direct children li for inner ol [OK]
Common Mistakes:
Thinking child selector ignores nested ol
Confusing semicolon error with selector issue
Believing CSS lacks child selector support
5. You want to style only the <span> elements that are direct children of <div class='container'>, but not <span> inside nested elements. Which CSS selector achieves this?
hard
A. .container > span
B. .container ~ span
C. .container + span
D. .container span
Solution
Step 1: Understand the requirement
Only <span> elements directly inside <div class='container'> should be styled, excluding nested spans.
Step 2: Choose correct selector
The child selector > selects direct children only, so .container > span matches only spans directly inside the container div.
Final Answer:
.container > span -> Option A
Quick Check:
Child selector > selects direct children only [OK]
Hint: Use > after parent class to select direct child elements only [OK]
Common Mistakes:
Using space selects all descendants, not just direct children