1

HTML

<ul>
  <li>one</li>
  <li>two</li>
  <li>
    <ol>
      <li>three</li>
      <li>four</li>
      <li>five</li>
    </ol>
  </li>
</ul>

I want the ultimate target of this train of selectors to be <li>five</li>? FWIW, no purple shows anywhere.

ul > li + ol > li {
    /*
        nested lists
    */

    background-color: purple;   /* just for testing */
}

Isn't the order of searching left to right?

  1. (ul>li)
  2. (ul>li) + ol
  3. ((ul>li) + ol) > li

If so, isn't the ultimate target <li>five</li> ???

ray
  • 26,557
  • 5
  • 28
  • 27

2 Answers2

2

Your ol is a child of li, not a sibling.

ul > li > ol > li {
  background: purple;
  color: white;
}
<ul>
  <li>one</li>
  <li>two</li>
  <li>
    <ol>
      <li>three</li>
      <li>four</li>
      <li>five</li>
    </ol>
  </li>
</ul>
ray
  • 26,557
  • 5
  • 28
  • 27
0

You could try the nth-of-type selector to select the exact element.

ul li ol li:nth-of-type(3) {
  background-color: purple
}
<ul>
  <li>one</li>
  <li>two</li>
  <li>
    <ol>
      <li>three</li>
      <li>four</li>
      <li>five</li>
    </ol>
  </li>
</ul>
skovy
  • 5,430
  • 2
  • 20
  • 34