Answer the question
In order to leave comments, you need to log in
How to work with BEM and Sass in the case of nested elements?
How to make friends between BEM and Sass in the case of nested elements and the need to style according to a pseudo-class (for example, hover)? Here is an example situation:
<div class="block">
<div class="block__element-1">
<div class="block__element-2">
</div>
</div>
</div>
.block {
&__element-2 {
...
}
&__element-1 {
...
&:hover {
/* Стили element-2 */
}
}
}
Answer the question
In order to leave comments, you need to log in
.block {
&__element-2 {}
&__element-1 {}
&__element-1:hover &__element-2 {}
}
.block {
$this: &;
&__element-2 {}
&__element-1 {
&:hover #{$this}__element-2 {}
}
}
and as the nesting increases, the situation worsens.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question