Answer the question
In order to leave comments, you need to log in
How to cascade with BEM?
Hello. I'm trying to use BEM in layout.
Sometimes you need to react to the events of parent elements and from this change the properties of child elements. In my hands with BEM it looks a bit ugly. Let me give you an example:
There is a product element with a picture and description. By default, the product image is 90% translucent. When you hover over the card, the picture should become opaque.
I'm using LESS, the code looks something like this:
<div class="cart">
<div class="cart__avatar"><img src="./pic.jpg" /></div>
<div class="cart__body">
Описание позиции
</div>
</div>
.cart {
&__avatar {
img {
opacity: .9;
}
}
&__body {
width: 50px;
}
&:hover {
.cart__avatar img {
opacity: 1;
}
}
}
Answer the question
In order to leave comments, you need to log in
If you follow the BEM methodology your code should look like this
<div class="cart">
<div class="cart__avatar">
<img class="cart__img" src="./pic.jpg" />
</div>
<div class="cart__body">
Описание позиции
</div>
</div>
.cart {
&__img{
opacity: .9;
}
&__body {
width: 50px;
}
&:hover {
.cart__img {
opacity: 1;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question