I have a peculiar want. The last three children in an li. I wish to target them only. Is it possible to do so?
I guess I could do them individually like so:
but I would rather not, is there a way around this?
Nope…the code you gave is the way to go unless you add a specific class or use JS
This reply has been reported for inappropriate content.
Thought as much, kinda sucks you can’t select up to a point really. What if I needed to get up to 100? I know it’s unlikely, but still. Oh well.
Thank you. =]
I was about to go the same route: giving all elements a certain style (the one you want for the last X element) and then use another style on top of that, EXCLUDING the last three.
Damn…that works…tried it a different way and couldn’t get it.
@jamy_za’s solution works great. Another tip, if you wanted to specifically target the last three (instead of everything but the last three), you can use this:
:nth-last-child(-n + 3)
@joshuanhibbert THAT’s what I was trying to figure out. I KNEW there was a ‘minus’ in there somewhere.
Well this is certainly solved. Thank you everyone. CSS is a sly fox sometimes. You would expect the minus symbol to be before the number.
You must be logged in to reply to this topic.
Search for Stuff
Browse the Archives
Get the Newsletter
... or get the RSS feed