0
0
CSSmarkup~20 mins

Child selector in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Child Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Which CSS rule applies only to direct children?
Given the HTML structure:
<div>
  <p>Paragraph 1</p>
  <section>
    <p>Paragraph 2</p>
  </section>
</div>

Which CSS selector will style only the <p> inside the <div> but not the <p> inside the <section>?
Adiv > p { color: red; }
Bdiv p { color: red; }
Cdiv + p { color: red; }
Ddiv ~ p { color: red; }
Attempts:
2 left
💡 Hint
The child selector uses a special symbol between parent and child.
🧠 Conceptual
intermediate
1:30remaining
What does the child selector target?
In CSS, what does the child selector (>) select?
AAll descendants of an element, no matter how deep
BOnly sibling elements that come after an element
COnly the first child of an element
DOnly the immediate children of an element
Attempts:
2 left
💡 Hint
Think about the difference between '>' and a space in selectors.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this child selector
What error does this CSS code cause?
div > > p { color: blue; }
CSS
div > > p { color: blue; }
ATypeError: unexpected token '>'
BSyntaxError: double '>' is invalid
CNo error, styles paragraphs inside div
DSelector matches all p elements
Attempts:
2 left
💡 Hint
Check the number of '>' symbols in the selector.
rendering
advanced
2:00remaining
What color will the text be?
Given this HTML:
<ul>
  <li>Item 1</li>
  <li>
    Item 2
    <ul>
      <li>Subitem 1</li>
    </ul>
  </li>
</ul>

And this CSS:
ul > li { color: green; }

Which list items will appear green?
CSS
ul > li { color: green; }
AOnly 'Item 1' and 'Item 2' will be green
BOnly 'Subitem 1' will be green
CAll list items will be green
DNo list items will be green
Attempts:
2 left
💡 Hint
Remember the child selector targets immediate children only.
accessibility
expert
2:30remaining
Why use child selectors for accessibility styling?
When styling a navigation menu with nested lists, why is it important to use the child selector (>) instead of a descendant selector (space) for focus styles?
ABecause child selectors automatically add ARIA roles
BBecause descendant selectors do not work with keyboard navigation
CTo ensure only top-level menu items get focus styles, avoiding confusion for screen reader users
DTo make the menu items larger for better visibility
Attempts:
2 left
💡 Hint
Think about how users navigate nested menus and what styles they expect.