I
I
indeveloping2020-02-01 20:53:20
BEM
indeveloping, 2020-02-01 20:53:20

How to implement two blocks of the same style according to BEM?

There are two independent blocks: services and benefits. In terms of styling, they are all the same. The only thing that distinguishes them from each other is the content. How to implement them in this case according to BEM?

1. Leave everything as it is, and set both blocks to the same styles (duplicate).

.services {
  /* Стили */
}

.advantages {
  /* Стили */
}

<section class="services">
  <h2 class="heading">Услуги</h2>
  <ul class="services__list">
    <li>Услуга 1</li>
    <li>Услуга 2</li>
    <li>Услуга 3</li>
  </ul>
</section>

<section class="advantages">
  <h2 class="heading">Преимущества</h2>
  <ul class="advantages__list">
    <li>Преимущество 1</li>
    <li>Преимущество 2</li>
    <li>Преимущество 3</li>
  </ul>
</section>


2. Create one block with the name for example section, set styles for it once, and apply services and benefits to the blocks

.section{
  /* Стили */
}

<section class="section">
  <h2 class="heading">Услуги</h2>
  <ul class="section__list">
    <li>Услуга 1</li>
    <li>Услуга 2</li>
    <li>Услуга 3</li>
  </ul>
</section>

<section class="section">
  <h2 class="heading">Преимущества</h2>
  <ul class="section__list">
    <li>Преимущество 1</li>
    <li>Преимущество 2</li>
    <li>Преимущество 3</li>
  </ul>
</section>


I lean towards the first option, since the block itself and its content are important, not its style. Indeed, in theory, the styles of these blocks can change on different pages. But I would like to hear other opinions and arguments.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mahmudchon, 2020-02-01
@mahmudchon

What if:

.section{
  /* Стили общие */
}
.services {
  /* Стили свои */
}

.advantages {
  /* Стили свои  */
}

<section class="section services">
  <h2 class="heading">Услуги</h2>
  <ul class="services__list">
    <li>Услуга 1</li>
    <li>Услуга 2</li>
    <li>Услуга 3</li>
  </ul>
</section>

<section class="section advantages">
  <h2 class="heading">Преимущества</h2>
  <ul class="advantages__list">
    <li>Преимущество 1</li>
    <li>Преимущество 2</li>
    <li>Преимущество 3</li>
  </ul>
</section>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question