Combinator and grouping selectors, online
Six activities your students do on their own devices. See who's finished, and their scores.
Combinator and grouping selectors in one minute
What students need to know
The > child combinator restricts the match to direct children, which 'ul > li' demonstrates. The + adjacent sibling combinator selects the element right after its sibling, as 'h2 + p' shows.
A comma groups selectors so they share one set of declarations. > selects direct children only; a space selects descendants at any depth.
Mistakes students make
- The comma groups selectors, so this targets every <article> and every <p> separately. To target paragraphs inside an article, use a space (descendant combinator): 'article p'.
- Line 1 ends with a period, which starts a class selector and breaks the group. Each grouped selector is separated by a comma: 'h2,'.
- Line 2 has two child combinators in a row, which is invalid. Use a single '>': 'main > a'.
- Two adjacent sibling symbols in a row are invalid. Use one '+': 'div + p'.
What students will learn in this module
Every question in Module 38
Quick questions
- Which selector targets every <p> nested anywhere inside a <div>?Adiv > pBdiv p
- True or False: 'h1, h2' applies the same rule to both h1 and h2.ATrueBFalse
- Which symbol selects the element immediately after a sibling?A~B+
- Which targets only the direct child <li> of a <ul>?Aul > liBul li
- True or False: 'h2 ~ p' selects every <p> that follows an <h2> and shares its parent.ATrueBFalse
Key terms
Students type the meaning of:
div p
Match the pairs
div pMatch it to what it doesh1, h2, h3Match it to what it doesSelects only the direct child elements of a parentMatch it to what it doesSelects the element immediately after a siblingMatch it to what it doesdiv > > p { }Match it to what it doesh2 + + p { }Match it to what it doesFill in the blanks
div _ p { color: red; }Hint: Type the child combinator symbol that matches direct children only
h1 _ p { margin: 0; }Hint: Type the adjacent sibling combinator symbol
h1, h2, __ { color: teal; }Hint: Type the next heading selector to continue the comma-separated group
h2 _ p { color: gray; }Hint: Type the general sibling combinator symbol
header a, footer _ a { color: navy; }Hint: Type the child combinator symbol that matches direct children only
Spot the error
Question 1
Aarticle, p {B color: navy;C}
Question 2
Ah1,Bh2.Ch3 {D margin: 0;E}
Question 3
Aheader a,Bfooter a,Cmain > > a {D color: blue;E}
Question 4
Adiv + + p {B margin-top: 0;C}
Question 5
Aul li,Bol, li {C color: red;D}
