Home > Net >  Multiple Child Selector CSS
Multiple Child Selector CSS

Time:10-28

If I have the following code :

<ul>
    <li>Unordered item</li>
    <li>Unordered item
        <ol>
            <li>Item 1</li>
            <li>Item 2</li>
        </ol>
    </li>
</ul>

How can I access Item 2 using :nth-child selector without using :last-child?

Thank you.

CodePudding user response:

Using nth-child(2)

ol li:nth-child(2){
color:red;}
<ul>
    <li>Unordered item</li>
    <li>Unordered item
        <ol>
            <li>Item 1</li>
            <li>Item 2</li>
        </ol>
    </li>
</ul>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

You can access like this

ol li:nth-child(2)

or

ul ol li:nth-child(2)
  • Related