×

css · level 3 · unit 3 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Combinators make :has() precise: > and +.

A is the symbol between two selectors that says how the elements are related. You know the space: anywhere inside. The , >, means directly inside, so .card:has(> img) only counts images that are the card's own children.

The , +, means straight after, in the same parent. h2:has(+ p) styles a heading that is followed right away by a paragraph.

Mix in :nth-child to count: ul:has(> li:nth-child(4)) matches lists with four items or more, so long lists can change their layout.

<h2>Opening hours</h2>
<p>Monday to Friday, 9 till 5.</p>
<h2>Find us</h2>
<ul>
  <li>12 Mill Lane</li>
</ul>
h2:has(+ p) {
  margin-bottom: 4px;
  color: #0f766e;
}

Press show my page to see it here.