Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CSS style the last element in a document

CSS style the last element in a document

Problem

In the following code I want to add styling specifically to the content of the last "B".

I am foo.
I like bars.
Actually, call me FOOBAR.

I have been trying

.B:last-of-type { color: red; }

and all classes "B" get selected because it uses the last occurence in it's immediate parents child elements. i.e. in it's direct siblings

Is there any way to only select the last occurence of "B" in the whole document?

Problem courtesy of: collinglass

Solution

Found the answer! CSS3 get last element

I was doing a version of this but I found it ugly, I guess this is the only way. I will keep this Question open for a bit to see if anyone has any better suggestions.

Solution courtesy of: collinglass

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

CSS style the last element in a document

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×