tags:

views:

32

answers:

1

I've got several p tags in the content of a page. I want to change the color of the last one before the div that hold them. Can I do this just with CSS?

<div class="text">
   <p>P One</p>
   <p>P Two</p>
   <p>P Three</p>
   <p>P Four (this is the one I'd like to modify)</p>
</div>

Thanks

+3  A: 

The easy, portable way:

<p class="last">P Four (this is the one I'd like to modify)</p>

.text p.last {}

The easy, less-portable way uses :last-child:

.text p:last-child {}

Or :last-of-type:

.text p:last-of-type {}
Roger Pate
Here's a support chart for `:last-child`: http://reference.sitepoint.com/css/pseudoclass-lastchild
Max Shawabkeh
Thanks Roger! I'll use the second example because I'm loading the text dynamically
Luli