Can I change the styles of the last p with CSS only?

I have several p-tags in the content of the page. I want to change the color of the last one in front of the div that is holding them. Can I do this with CSS only?

<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

+2


a source to share


1 answer


Simple, portable way:

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

.text p.last {}

      

A simpler, less portable way is using : last-child :



.text p:last-child {}

      

Or : last-of-type :

.text p:last-of-type {}

      

+3


a source