Search code examples
cssparenttarget

css :target on children


Suppose we have this html

<div class="a">
   <div>...</div>
   ...
   <div id="b">xyz</div>
</div>


<div class="a">
   <div>...</div>
   ...
   <div id="c">abc</div>
</div>

Applying some style on #b upon targeting it in url is easy to do with the css :target selector. Is it possible to apply some some style on the parent div with class="a" as well?


Solution

  • No, since you would need a CSS parent selector for that. Nothing in CSS2 and CSS3 has been specified for that. CSS4 does have (a somewhat) parent selector (called the subject selector) using the ! symbol, but no browser supports it (yet).