I thought the following selector would only match example b. Can someone explain to me a little more about how CSS paths work?
body div span a{
background:#000;
color:#fff;
}
<body>
<div><span><span><a href="#">example a</a></span></span></div>
<div><span><a href="#">example b</a></span></div>
<span><div><span><a href="#">example c</a></span></div></span>
</body>
A visual example or a more elaborated tree/paths with “this will be affected”, “this won’t” would be extremely helpful to me. A link to a good guide could also be interesting.
See the W3C specification for more information.
To simplify your example, a selector
div a { }will match any<a>tag which descends from a<div>tag, regardless of how many levels of ancestry separate the two tags.That is,
div a { }will match any of the following:If you want to match an
<a>contained directly within a<div>with no other tags separating them, you need to usediv > a, which matches only<a>tags that are direct descendants of a<div>tag.