skip to Main Content

How to select <figure> only when it contains <iframe>?

I need to select this figure:

<figure>
   <iframe></iframe>
</figure>

3

Answers


  1. Chosen as BEST ANSWER
    figure:has(iframe)
    

    does this trick


  2. You can use the :not selector:

    figure:not(:empty):not(:has(img)) {
      /* Your styles here */
    }```
    
    Login or Signup to reply.
  3. You could use :has() pseudo-class:

    figure:has(iframe) {
      background-color: red;
    }
    <figure>
      With iframe
      <iframe></iframe>
    </figure>
    <figure>
      With image
      <img>
    </figure>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search