[CSS 3] :has selector

html:

    <div class="post">
      <h2>Post</h2>
      <a href="#"> a link</a>
    </div>
    <div class="post">
      <h2>Post</h2>
    </div>
    <div class="post">
      <a href="#"> a link</a>
    </div>

Want to target the .post has <h2>, also has <a>

.post:has(h2):has(a) {
   background: red;
 }

 

posted @ 2023-07-06 03:01  Zhentiw  阅读(16)  评论(0)    收藏  举报