Answer the question
In order to leave comments, you need to log in
How should block modifiers behave in BEM?
Hello. Let's say I have a conditional modal:
<div class="modal">
<div class="modal__title"></div>
<div class="modal__content"></div>
</div>
.modal--small{...};
.modal--small .modal__title{...}
.modal--small .modal__content{...}
<div class="modal modal--small">
<div class="modal__title"></div>
<div class="modal__content"></div>
</div>
.modal--small{...};
.modal__title--small{...}
.modal__content--small{...}
<div class="modal modal--small">
<div class="modal__title modal__title--smal"></div>
<div class="modal__content modal__content--small"></div>
</div>
Answer the question
In order to leave comments, you need to log in
1 вариант безусловно. Не стоит прям очень фанатично следовать всем правилам бема.
В любом препроцессоре потом будет удобно писать что-то в стиле:
.modal {
&__title {
//styles
.modal--small & {
// styles for small modal
}
}
}
BEM doesn't have cascades, does it?
Is not
<div class="modal--small">
<div class="modal--small__title"></div>
<div class="modal--small__content"></div>
</div>
From the point of view of naming principles, in the first case you described a modifier for a block, in the second - three different modifiers with the same name (for a block and for each element). In your situation, the first option is more suitable.
BEM does not prohibit describing style cascades, but it does not recommend making selectors for a chain of several blocks (because in this case the blocks begin to depend on each other). In your case, the classes of the block and its elements are indicated in the cascades - this is quite normal.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question