I’ve often wondered why this doesn’t exist already as I am not the first to think this would be useful. Perhaps there’s some implementation technicalities that I’ve not considered (most likely!).
On occasion you may have a list of similar elements followed by an element which is not so similar. If you want to style the last element of your “similar” elements you can’t use :last-child. Here’s a really simple example. In this example, imagine you want to remove the border of the last “thing”. You can’t use :last-child because that matches the
Of course there are many workarounds for this limitation. Notably the following spring to mind:
“Add another class to the last item”
“wrap the elements which are similar in some other element (perhaps an
(un)ordered list for semantics) and then use last-child”
While these are of course perfectly valid, and in some situations will actually be a better or (arguably) more semantic solution, sometimes it’s extra hassle that could easily be avoided if we had something like :last-of-class(‘thing’)
Are there issues with this proposal that I might have not considered?