htmlの条件構造をテキストにしてみましょう
.sort-activeを内包する.hogehoge-contentを内包する#page-wrapperにスタイルを充てたい
要素を分解して条件を整理してみましょう
#page-wrapper {
スタイルを充てたいのはここ【条件1】
}
:has(.sort-active) {
.sort-activeを内包していることを条件にしたい【条件2】
ただしこの条件は他のページにも影響してしまう
}
:has(.hogehoge-content) {
.hogehoge-contentを内包していることを条件にしたい【条件3】
この条件であれば独自性を保てるため他ページへ影響しない
}
.hogehoge-content:has(.sort-active) {
.sort-activeを内包する.hogehoge-contentという条件が構造上必要である【条件4】
}
つまり【条件4】を内包する【条件1】という形に出来ればよいので
【条件1】:has(【条件4】) {
〜
}
↓
#page-wrapper:has(.hogehoge-content):has(.sort-active) {
〜
}
実は条件構造がテキスト化出来ればあとは改行による分解と逆から読んで組み立てるだけで良かったりします
【1】.sort-activeを内包する
【2】.hogehoge-contentを内包する
【3】#page-wrapper
↓
【3】#page-wrapper
【2】:has(.hogehoge-content)
【1】:has(.sort-active)
↓
#page-wrapper:has(.hogehoge-content):has(.sort-active) {
〜
}
また、Sassのようにcssを入れ子構造で書いてもわかりやすいかもしれないですね
#page-wrapper {
&:has(.hogehoge-content) {
&:has(.sort-active) {
〜
}
}
}
htmlと同じ構造であるというのが理解しやすいと思います
See the Pen Untitled by southkey47 (@southkey47) on CodePen.