Seems like a perfect use case for a pseudo with
Although reading back your additional description is indeed slightly confusing…
Edit – in retrospect I think I may have misunderstood altogether. Is your question maybe if HTML/CSS can recognise the content of a
h element? In that case the answer would be negative. Then again, simplest way would be to give them a common class and style that.
But maybe you could elaborate a bit more on the expected result.
My suggestion above would be a nice alternative for the example page though.
Second edit – this might be an approach too: