This is a purely hypothetical situation. Answering a question yesterday, I ran into a problem that I had not encountered before. The question itself was rather erroneous in that you simply would not have done what he was trying to achieve, but this problem may appear in other situations. I could not give a working answer that is not related to changing the markup, and I would like to know if this is possible without changing the markup.
Take this example:
<p><strong>Lorem</strong> ipsum dolor <strong>sit</strong> amet...</p>
To create the first element strong, you simply use p > strong:first-childor something similar. It works great and works well, but what if the first one strongwas optional, and it was only the first strongone that would require styling?
<p>Lorem ipsum dolor <strong>sit</strong> amet...</p>
Is it possible to guarantee that only the very first tag will be used here strongwithout the use of classes, identifiers or anything that could distinguish two tags strongthrough markup?
Here's the JSFiddle of the above .
: , , . , p:first-child . strong - strong.
: JSFiddle, , .