2

How have can I set styles for the last list element of the nested list. I want these styles to be applied only to elements with the class "match".

Here is the code example:

HTML:

<ul>
    <li>
        <ul>
            <li class="match">x1 match</li>
            <li class="match">y1 match</li>
            <li>z1</li>
        </ul>
    </li>
    <li>
        <ul>
            <li>x2 match</li>
            <li class="match">y2 match</li>
            <li>z2</li>
        </ul>
    </li>
    <li>
        <ul>
            <li class="match">x3 match</li>
            <li class="match">y3 match</li>
            <li class="match">y3 match</li>
        </ul>
    </li> 
</ul>

CSS:

ul li ul li:last-of-type {
    color: red;
}

http://jsfiddle.net/RYz6e/1/

To be specific in this example I want next items to be selected:

  • y1 match
  • y2 match
  • y3 match

Thank you

And1
  • 33
  • 1
  • 6

3 Answers3

0

Try this:

ul li ul .match:nth-of-type(even)
{
    color: red;
}

Fiddle

This won't work if more elements come.

Leo T Abraham
  • 2,407
  • 4
  • 28
  • 54
  • No, there is *no* 'pure solution...with CSS,' (was that a typo?) and if you're suggesting jQuery (why not plain JavaScript?) then at least offer that solution. – David Thomas Apr 28 '14 at 11:46
  • @DavidThomas I have found a solution. But it will not work if more elements come. – Leo T Abraham Apr 28 '14 at 12:15
-2

try to like below using css3

ul li:last-child
    {
    color: red;
    }
-2

Or you could use:

ul .match {
color: red;
}    

For a shorter notation.

Anwardo
  • 650
  • 5
  • 15