I want to standardise the CSS I use, and am leaning towards bem — I know I'll get a lot of benefit from the predictability of its pattern.
I have hacked their formula ever so slightly - I don't include the B
part of the classname on child elements. For me this makes the html easier to write, and maintain.
Pure BEM
<ul class="Slideshow">
<li class="Slideshow__slide Slideshow__slide--is-active">
<img class="Slideshow__image" src="/blah" />
</li>
<li class="Slideshow__slide">
<img class="Slideshow__image" src="/blah" />
</li>
</ul>
.Slideshow {}
.Slideshow__slide {}
.Slideshow__image {}
My Modified BEM
<ul class="Slideshow">
<li class="slide slide--is-active">
<img class="image" src="/blah" />
</li>
<li class="slide">
<img class="image" src="/blah" />
</li>
</ul>
.Slideshow {}
.Slideshow .slide {}
.Slideshow .image {}
The only advantage I see to using 'pure' BEM over my modified version is the avoidance of conflict between child elements of different blocks (e.g. .Slideshow .image
and .AdvertBanner .image
).
This is not a problem for me, because I use LESS, nesting block level rules automatically.
Can anybody suggest other advantages to using 'pure' BEM over my modified version?