This is a purely hypothetical situation. When answering a question yesterday I came across a problem which I hadn't encountered before. The question itself was pretty flawed in that you simply wouldn't do what it was trying to achieve, but this problem may pop up in other situations. I wasn't able to give a working answer that didn't involve changing the markup, and I'd like to know if it's at all possible without changing the markup.
Take this example:
<p><strong>Lorem</strong> ipsum dolor <strong>sit</strong> amet...</p>
To style the first strong
element you'd simply use p > strong:first-child
or something similar. That's great and works well, but what if the first strong
was optional and it was only the first strong
that would require styling?
<p>Lorem ipsum dolor <strong>sit</strong> amet...</p>
Is it possible to ensure that only the very first strong
tag here would be styled without using classes, identifiers or anything that could differentiate the two strong
tags through the markup?
Here's a JSFiddle of the above.
Note: from the initial answers the question may have been a little misleading. The paragraph doesn't have to be the first on the page, so p:first-child
isn't a solution. The first paragraph may not have this leading strong
element - alternatively the second paragraph could also have this leading strong
element.
Edit: I've updated the JSFiddle example to give a little more clarity of what should and shouldn't be styled.