📜 ⬆️ ⬇️

BEM'a should not exist


Hello.

BEM should not exist. There are a huge number of reasons not to use this methodology, but because of its ease of use and lack of understanding of the work of CSS and HTML, the methodology has spread widely among the frontendors of the whole world, in most cases among the CIS developers. BEM is used now both on large Russian projects (Yandex, Habr), and in some frameworks ( react-md ). This article will go into a detailed analysis of the pros and cons of this approach to development. All examples of the layout will be taken from the official BEM website.



Abbreviation BEM - block / element / modifier. Any layout or design can be visually divided into blocks, for example - the sidebar of the site. Each block can contain one or more elements. Elements can have state modifiers (active, disabled), additional classes for changing borders, widths, background colors, etc.
')
The idea of ​​breaking the layout into blocks is not new, what BEM suggests is to extend the class names, always make the elements dependent on the block name and set any class globally. It helps literally anywhere and leads to dire consequences in the design of projects. The following are described by item problems in using BEM'a:

Unreadable html


This is the layout from the official BEM website. Extended and php-like CSS class names make any layout completely unreadable interspersed with attributes:

<ul class="article-rewind article-rewind_type_static article-rewind_lang_ru">
    <li class="article-rewind__next">
        <div class="article-rewind__next-text"> </div>
        <a class="article-rewind__next-link" href=""> </a>
   </li>
</ul>

, SCSS, :

<ul class="article-rewind type-static lang-ru">
    <li class="next">
        <div class="text"> </div>
        <a class="link" href=""> </a>
   </li>
</ul>

.article-rewind {
  margin:      0;
  padding:     0;
  list-style:  none;
  &.type-static {
    position:  relative;
    display:   flex;
  }
  &.lang-en {}
  &.lang-ru {}
  &.lang-uk {}
  & > .next {
    position:      relative;
    flex-grow:     1;
    align-self:    center;
    margin-right:  88px;
    text-align:    right;
    .text {
      font-size:   16px;
      position:    absolute;
      right:       0;
      margin-top: -32px;
    }
    .link {
      font-size:   40px;
      line-height: 46px;
    }
  }
}



BEM — , — . , CSS , , button active, disabled, error, , . — CSS :

    <h1 class="article__heading_level_1 article__heading_level_1_active"></h1>

SCSS, :

    <h1 class="heading active"></h1>

.article {
  h1.heading {
    font-size:   50px;
    line-height: 64px;
    float:       left;
    &.active {
      color:     #ccc;
    }
  }
}

— -


, . , . , promo-section_color_white — , .promo-section. . , :

  <div class="promo-section promo-section_color_white"></div>

html, - , :

  <div class="promo-section background-white"></div>

.promo-section {
  position: relative;
  padding:  0 0 70px;
}
.background-white {
  background-color: white;
}


:
CSS id
, mixin'a html- :

  <h1 class="article__heading article__heading_level_1"></h1>
  <h2 class="article__heading article__heading_level_2"></h2>
  <h3 class="article__heading article__heading_level_2"></h3>

h1,h2 , «article__heading_level_1».

  <h1 class="heading"></h1>
  <h2 class="heading"></h2>
  <h3 class="heading"></h3>

@for $index from 1 through 6 {
  h#{$index}.heading {
    font-size: (42px / $index);
  }
}

/* mixin output */
h1.heading {font-size: 42px;}
h2.heading {font-size: 21px;}
h3.heading {font-size: 14px;}
h4.heading {font-size: 10.5px;}
h5.heading {font-size: 8.4px;}
h6.heading {font-size: 7px;}


, , , , , .. , .
.
? BEM'a header'e , body. , , - .


. , CSS, . , .

:
hackernoon.com/bem-should-not-exist-6414005765d6

Source: https://habr.com/ru/post/422537/


All Articles