0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【CSS】特定のクラス名を持つ親要素の子要素にスタイルを当てる

Posted at

久々にCSSで詰まったのでメモ。

やりたいこと

特定のクラス名を持つ親要素の子要素にスタイルを当てたい。

<div class="parent --color">
  <p class="child">ここにだけスタイルを当てたい</p>
</div>

<div class="parent">
  <p class="child">ここには当てない</p>
</div>

お恥ずかしながら、:has()でいけるだろーって思ってた。

やり方

.parent[class*="--color"] .child { color: #699af8; }

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?