-1
<ul>
    <li class="special"></li>
    <li class="special"></li>
    <li class="special"></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

In this example I would like to target only the last .special list item. Is this possible using only CSS?

bernk
  • 1,155
  • 2
  • 12
  • 22

4 Answers4

0

You cannot achieve it by using pure CSS.

I'd suggest alternative way by using javascript, or more specific jQuery by utilizing :last selector:

$('ul li.special:last').css('color','red');

Fiddle Demo

Felix
  • 37,892
  • 8
  • 43
  • 55
0

Using css alone, check this out. Working Fiddle

li:nth-child(3){
color:#f00;
}
Binita Lama
  • 1,268
  • 1
  • 8
  • 16
0

Maybe it helps if you target the first non-special element like this:

ul .special + li:not(.special) { background: red; }
Iulian Anghel
  • 411
  • 2
  • 5
0

If you know it's always three items you could do something like this

.special + .special + .special {
    // your styles
} 
Colin Bacon
  • 15,436
  • 7
  • 52
  • 72