Luciano Blog

Software Technologies

CSS child and adjacent sibling combinator

The “ > “ greather symbol is the child combinator, and “selects elements direct descendants of the previous specified element”.

ol > li {
	color: red;
}
<ol>
  <li>WILL be selected</li>
  <li>WILL be selected</li>
  <ul>
     <li>Will NOT be selected</li>
     <li>Will NOT be selected</li>
  </ul>
  <li>WILL be selected</li>
</ol>

The “ + “ plus symbol is the adjacent sibling combinator, and “selects elements direct descendants after of the previous specified element (with nothing in between)”.

ol + li {
	color: red;
}
<ol>
  <li>WILL be selected</li>
  <li>WILL be selected</li>
  <br />
  <li>Will NOT be selected</li>
  <li>Will NOT be selected</li>
</ol>

Article from css-tricks.com