Complete the code to select only direct child <p> elements of a <div>.
div [1] p { color: blue; }The > symbol selects direct children only, so div > p targets
elements that are immediate children of a
Complete the code to color direct child <li> elements of a <ul> red.
ul [1] li { color: red; }The > selector targets only direct children, so ul > li colors only
- .
Fix the error in the selector to style only direct child <span> elements inside a <section>.
section [1] span { font-weight: bold; }The > selector ensures only direct child elements inside
Fill both blanks to select direct child <h2> elements inside <article> and color them green.
article [1] h2 { color: [2]; }
The > selects direct children, and green colors the text green.
Fill all three blanks to select direct child <a> elements inside <nav>, set text decoration to none, and color to blue.
nav [1] a { text-decoration: [2]; color: [3]; }
The > selects direct children, none removes underline, and blue colors the links blue.
Practice
> do?Solution
Step 1: Understand selector types
The child selector>targets only elements that are direct children of a specified parent.Step 2: Compare with other selectors
Unlike the descendant selector (space), it does not select nested grandchildren or deeper descendants.Final Answer:
Selects only direct child elements of a parent -> Option BQuick Check:
Child selector = direct children only [OK]
- Confusing child selector with descendant selector
- Thinking it selects siblings
- Assuming it selects all nested elements
<li> elements that are direct children of a <ul>?Solution
Step 1: Identify the child selector syntax
The child selector uses the>symbol between parent and child tags.Step 2: Match syntax to question
To select<li>elements directly inside<ul>, useul > li.Final Answer:
ul > li -> Option AQuick Check:
Correct child selector syntax = ul > li [OK]
- Using space instead of > selects all descendants
- Using + or ~ which select siblings, not children
- Missing the > symbol
<div>
<p>First</p>
<section>
<p>Second</p>
</section>
</div>And this CSS:
div > p { color: red; }Which
<p> elements will be red?Solution
Step 1: Identify direct children of <div>
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 CQuick Check:
Child selector affects direct children only [OK]
- Assuming all nested elements are selected
- Ignoring the nesting inside <section>
- Confusing descendant selector with child selector
<li> children of <ol> blue:ol > li { color: blue }But it colors all
<li> elements inside nested <ol> too. What is the problem?Solution
Step 1: Understand nested lists structure
Nested<ol>inside<li>creates new direct children<li>for the innerol.Step 2: Explain why all
The selector<li>get coloredol > limatches direct children of anyol, including nested ones, so all nestedliget colored.Final Answer:
Nested <ol> inside <li> causes deeper <li> to be direct children of inner ol -> Option DQuick Check:
Child selector matches direct children of each ol, including nested [OK]
- Thinking child selector ignores nested ol
- Confusing semicolon error with selector issue
- Believing CSS lacks child selector support
<span> elements that are direct children of <div class='container'>, but not <span> inside nested elements. Which CSS selector achieves this?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 > spanmatches only spans directly inside the container div.Final Answer:
.container > span -> Option AQuick Check:
Child selector > selects direct children only [OK]
- Using space selects all descendants, not just direct children
- Using + or ~ selects siblings, not children
- Missing the > symbol
