getbem / getbem.github.io

Get BEM to all people in simplest way
http://getbem.com/
MIT License
5.68k stars 220 forks source link

Clarify how to apply block modifiers to the elements #308

Open collimarco opened 1 year ago

collimarco commented 1 year ago

For example, if you have:

<div class="article article--featured">
  <h1 class="article__title"></h1>
</div>

Now I want to have a bigger h1 for the variant article--featured.

  1. Should I add the class article__title--featured to h1 if I want to apply some styles to that element for the variation?
  2. Or should I add a class article--featured__title?
  3. Or should I keep only the class article__title and style it in CSS using a descendant selector .article--featured .article__title?

This is not clear from the spec.

ghost commented 10 months ago

I'm not an expert but if I had to choose, I'd go for the first one. The other two make no sense for me. The second one implies there is a property with a block name indicator, which would break your naming in the future. BEM doesn't use other selectors other than class-based ones, so avoid descendant selectors if you want to keep everything fully BEM.