This snippet doesn't work the way I expect:
div li span:first-child {
font-weight: bold;
}
<div>
<ul>
<li><span>This is a test</span></li>
<li>And <span>this is also a test</span></li>
</ul>
</div>
Both span
elements are bold. I would have expected the 2nd one to not be bold, because it follows the plaintext "And "
, but I guess :first-child
doesn't consider text content to be a child.
Is there a way to differentiate these two situations, and select elements which are not preceded by any content or siblings?
To clarify: In my specific case, I want to make a <span>
element in each <li>
element bold, but only if it's right at the beginning of the <li>
and not preceded by any text or other elements.