According to this page, I can use the :last-of-type to select the last occurrence of the specified tag. I've tested it and it works if the elements are static in the HTML.
<style>
span:last-of-type { border: 1px solid pink; }
</style>
<span>A</span>
<span>B</span>
<span>C</span>
However, I don't get the same result when I generate the div inside another tag like this.
<div><span>A</span></div>
<div><span>B</span></div>
<div><span>C</span></div>
I mean to do something with the SPAN and style it, not the DIV but only on the last occurrence of P and not each. I've tried something like this (and a few other variants) but nothing gave me the desired selection.
div:last-of-type span { border: 1px solid pink; }
div:last-of-type > span { border: 1px solid pink; }
div:last-of-type span:last-of-type { border: 1px solid pink; }
I've seen this answer but it's not accepted and it seems not to work when I follow it.
I also noticed that the corresponding :first-of-type behaves as expected, so I'm suspecting that my query selects the last DIVregardless of whether it contains a SPAN. And in there, there's no SPAN to be bordered, of course.
How would I say "the last division of all divisions on the page containing a span and use said span for bordering"?