<article class="some-class">
  <div class="some-class"></div>
</article>
@layer base;

article:has(.some-class, #id, img) {
  background: #000;
}

article .some-class {
  background: #fff;
}

@layer base {
  body {
    display: grid;
    place-items: center;
    height: 100dvh;
  }

  article {
    aspect-ratio: 1;
    width: 250px;
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.