Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a descendant selector in CSS?
A descendant selector targets elements that are inside another element, no matter how deep. It uses a space between selectors to show this relationship.
Click to reveal answer
beginner
How do you write a descendant selector to style all span elements inside a div?
You write it as div span { /* styles here */ }. This means any span inside a div will get the styles.
Click to reveal answer
beginner
True or False: The descendant selector only selects direct children elements.
False. The descendant selector selects all elements inside another element, at any level, not just direct children.
Click to reveal answer
beginner
Example: What elements does this selector target? article p
It targets all p elements that are inside an article element, no matter how deeply nested.
Click to reveal answer
intermediate
Why use descendant selectors instead of just class or id selectors?
Descendant selectors help style elements based on their location inside other elements. This keeps CSS organized and avoids adding many classes or ids.
Click to reveal answer
Which CSS selector targets all li elements inside a ul?
Aul > li
Bul + li
Cli ul
Dul li
✗ Incorrect
The descendant selector 'ul li' selects all
elements inside any
, at any depth.
What does the space between selectors mean in CSS?
AAdjacent sibling
BDirect child only
CDescendant relationship
DNo relation
✗ Incorrect
A space between selectors means the second element is a descendant (child, grandchild, etc.) of the first.
Which selector matches only direct children?
Adiv span
Bdiv > span
Cdiv + span
Ddiv ~ span
✗ Incorrect
The '>' symbol selects only direct children, not all descendants.
If you want to style all paragraphs inside a section, which selector is correct?
Asection p
Bp section
Csection > p
Dsection + p
✗ Incorrect
'section p' selects all paragraphs inside a section, no matter how deep.
True or False: Descendant selectors can select elements nested multiple levels deep.
ATrue
BFalse
COnly one level deep
DOnly siblings
✗ Incorrect
Descendant selectors select elements nested at any depth inside another element.
Explain what a descendant selector is and how it works in CSS.
Think about how you find something inside a box inside a bigger box.
You got /3 concepts.
Describe the difference between a descendant selector and a child selector in CSS.
One is like any family member inside a house, the other is only the children living directly in the house.
You got /3 concepts.
Practice
(1/5)
1. What does the CSS descendant selector div p do?
easy
A. Selects only <p> elements that are direct children of <div> elements.
B. Selects all <p> elements and <div> elements separately.
C. Selects all <div> elements that are inside <p> elements.
D. Selects all <p> elements inside any <div> elements, no matter how deep.
Solution
Step 1: Understand the descendant selector syntax
The space between div and p means select p elements inside div elements at any depth.
Step 2: Differentiate from child selector
The child selector uses > and selects only direct children, but here it's a space, so all nested p inside div are selected.
Final Answer:
Selects all <p> elements inside any <div> elements, no matter how deep. -> Option D
Quick Check:
Descendant selector = space = nested elements [OK]
Hint: Space means any nested element inside another [OK]
Common Mistakes:
Confusing descendant selector with child selector
Thinking it selects only direct children
Mixing up order of selectors
2. Which of the following is the correct syntax for selecting all <span> elements inside <section> elements using a descendant selector?
easy
A. section span
B. section > span
C. section+span
D. section, span
Solution
Step 1: Recall descendant selector syntax
The descendant selector uses a space between selectors to select nested elements.
Step 2: Analyze each option
section > span uses child selector (>), section+span uses adjacent sibling (+), section, span selects both separately with a comma. Only section span uses a space correctly.
Final Answer:
section span -> Option A
Quick Check:
Space = descendant selector syntax [OK]
Hint: Use space between selectors for descendants [OK]
The selector div p selects all p elements inside any div, at any depth.
Step 2: Check HTML structure
Both p elements are inside the div: one inside article (nested), one directly inside div.
Final Answer:
Both <p> elements inside <div> will be red -> Option A
Quick Check:
Descendant selector selects all nested matches [OK]
Hint: Descendant selector selects all nested matches [OK]
Common Mistakes:
Thinking only direct children are selected
Ignoring nested elements inside other tags
Assuming only first matching element is styled
4. Consider this CSS rule:
ul li a { text-decoration: none; }
But the links inside list items are still underlined. What is the most likely problem?
medium
A. The selector is incorrect; it should be ul > li > a.
B. The a elements are not inside li elements.
C. There is a more specific CSS rule overriding this one.
D. CSS does not support descendant selectors.
Solution
Step 1: Understand the selector
The selector ul li a correctly targets a inside li inside ul.
Step 2: Consider CSS specificity and overrides
If links remain underlined, likely another CSS rule with higher specificity or inline style overrides this rule.
Final Answer:
There is a more specific CSS rule overriding this one. -> Option C
Quick Check:
Overrides cause expected styles to fail [OK]
Hint: Check for more specific CSS rules overriding yours [OK]
Common Mistakes:
Assuming descendant selector syntax is wrong
Not checking for CSS specificity conflicts
Ignoring inline styles or browser defaults
5. You want to style all <em> elements inside <article> elements, but only if they are inside a <section> inside that <article>. Which CSS selector correctly targets this?
hard
A. article em section
B. article section em
C. article > section > em
D. section article em
Solution
Step 1: Understand the nesting order
The em is inside section, which is inside article. So the order is article then section then em.
Step 2: Analyze each selector
article section em uses article section em which matches em inside section inside article. section article em reverses order incorrectly. article > section > em uses child selectors which may be too strict. article em section is invalid order.
Final Answer:
article section em -> Option B
Quick Check:
Descendant selector order matches nesting order [OK]
Hint: Write selectors in ancestor to descendant order [OK]
Common Mistakes:
Reversing selector order
Using child selectors when descendants are nested deeper