What is an acceptable way to deal with this use of BEM?
Depends on which version of BEM you are using. I use the BEM pre-specification option , which means that you will have different answers if you follow bem.info .
Modifiers must be attached to the element that they are modifying. However, modifying the block allows the modifier to be inherited by children:
<div class="foo foo--example"> <div class="foo__bar foo--example__bar">...</div> <div>
This gets messy when the children also have modifiers:
<div class="foo foo--example"> <div class=" foo__bar foo--example__bar foo__bar--another-example foo--example__bar--another-example">...</div> <div>
This form of BEM syntax is pretty verbose. It is best used for generated code.
I use LESS for CSS preprocessing, so my BEM code often looks like this:
.foo { ... &__bar { ... } }
With modifiers it becomes:
.foo { ... &__bar { ... } &--example { ... &__bar { ... } } }
This ensures that the cascade is in the correct order and that all selectors continue to have exactly one class.
source share