Hello. Trying to use BEM in the layout.
Sometimes you need to respond to events of parent elements and to change the properties of child elements. In my hands with the BEM, it looks a bit ugly. Here is an example:
There is an element item with picture and description. The default item picture translucent to 90%. When you hover on the card, the picture should become opaque.
I use LESS, the code looks like this:
<div class="cart">
<div class="cart__avatar"><img src="./pic.jpg"></div>
<div class="cart__body">
Item description
</div>
</div>
.cart {
&__avatar {
img {
opacity: .9;
}
}
&__body {
width: 50px;
}
&:hover {
.cart__avatar img {
opacity: 1;
}
}
}
Do I do with the :hover selector image when hovering?
Is he really supposed to look bad?
remains, and from it can not escape? - layne51 commented on June 10th 19 at 15:09
- maryjane.Corkery commented on June 10th 19 at 15:12
Then your code will look like this
But it is very expensive to catch all events using js to add classes. - milan.Purdy commented on June 10th 19 at 15:21
In General, a particularly beautiful way, using LESS, apparently, is not. - layne51 commented on June 10th 19 at 15:24