Answer the question
In order to leave comments, you need to log in
How to properly use modifiers in BEM methodology?
Get used to getting to the right element with a variety of CSS tools without using the BEM methodology. But how do you get to an element using this methodology when you need, for example, the first or last element, or even or odd elements, or specific elements? Well, if necessary, select the first and last element, then of course you can hang the modifier as an additional class, but I don’t know if this is right. And what about in other cases?
Answer the question
In order to leave comments, you need to log in
It depends on the situation, if possible, it is better to use a modifier.
BEM solves the problem of specificity well, making behavior more predictable.
For example, we have some block (or element, it doesn’t matter) .box__item and we want to add an indent to the left first, like this:
.box__item:first-child {
margin-left: 10px;
}
@media (min-width: 720px) {
.box__item {
margin-left: 20px;
}
}
.box__item,
.box__item:first-child {
margin-left: 20px;
}
It is quite normal to use :first-child
, etc. for an element. If we are talking about a block, then it should no longer know about its location.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question