0
0
CSSmarkup~5 mins

Complex selector combinations in CSS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the CSS selector div > p select?
It selects all <p> elements that are direct children of a <div> element.
Click to reveal answer
beginner
Explain the difference between div p and div > p selectors.
div p selects all <p> elements inside a <div>, no matter how deep.<br>div > p selects only <p> elements that are immediate children of the <div>.
Click to reveal answer
intermediate
What does the selector ul li:first-child target?
It targets the first <li> element inside each <ul> list.
Click to reveal answer
intermediate
How does the adjacent sibling selector h2 + p work?
It selects the first <p> element immediately following an <h2> element, only if they share the same parent.
Click to reveal answer
intermediate
What is the purpose of the general sibling selector h2 ~ p?
It selects all <p> elements that are siblings of an <h2> element and come after it, regardless of how many elements are in between.
Click to reveal answer
Which selector matches all <li> elements inside a <ul>, no matter how deeply nested?
Aul + li
Bul > li
Cul li
Dul ~ li
What does the selector p:first-child select?
AThe first <code>&lt;p&gt;</code> in the document
BEvery <code>&lt;p&gt;</code> that is the first child of its parent
CAll <code>&lt;p&gt;</code> elements
DThe first <code>&lt;p&gt;</code> inside a <code>&lt;div&gt;</code>
Which selector selects only <p> elements immediately after an <h1>?
Ah1 + p
Bh1 > p
Ch1 p
Dh1 ~ p
What does the selector section > article.highlight select?
AAll <code>&lt;article&gt;</code> elements with class <code>highlight</code> that are direct children of <code>&lt;section&gt;</code>
BAll <code>&lt;article&gt;</code> elements inside <code>&lt;section&gt;</code> siblings
CAll <code>&lt;section&gt;</code> elements with class <code>highlight</code>
DAll <code>&lt;article&gt;</code> elements with class <code>highlight</code> inside any <code>&lt;section&gt;</code>, at any depth
Which selector matches all siblings <p> after an <h3>?
Ah3 > p
Bh3 p
Ch3 + p
Dh3 ~ p
Describe how you would select all paragraphs that are direct children of a div using CSS selectors.
Think about the symbol that means 'direct child' in CSS.
You got /4 concepts.
    Explain the difference between the adjacent sibling selector and the general sibling selector in CSS.
    One selects only the next sibling, the other selects all siblings after.
    You got /5 concepts.