次の設定があるとしましょう。
.block
.block__header
.block__content
.block__footer
次に、このブロックのアクティブな状態を表示したいと思います。ブロック自体が緑の背景になり、要素 2 と 3 が太字のテキストになるとします。BEM の哲学を理解しているので、特異性をできるだけ低く保つために、子セレクターを使用しないでください。
それで、これは本当にそれを行う方法ですか?
.block.block--active
.block__header
.block__content.block__content--active
.block__footer.block__footer--active
更新:そして、SASSでそのソリューションをどのように記述しますか(非常に新しい)? これまでの私のセットアップ...ネストされたセレクターを使用できる場合、ここでのベストプラクティスは何ですか?
.block {
&--active {
}
&__header {
}
&__content {
// active modifier of content
&--active {
font-weight: bold;
}
// would be the same as
.block--active & {
font-weight: bold;
}
// but can i reference the active block somehow else in sass?
// & is a parent selector but i would need the parent of the parent here...
}
&__footer {
&--active {
}
}
}