S
S
Sergey Goryachev2016-10-22 21:37:42
css
Sergey Goryachev, 2016-10-22 21:37:42

How to properly format a BEM block?

There is a simple code:

<!-- slider -->
<aside class="slider">
    <div class="wrapper">
        <!-- slider-title -->
        <div class="slider-title">
            <h2>Натяжные потолки</h2>
            <h3>Установка качественных и долговечных потолков по отличным ценам</h3>
        </div>
        <!-- /slider-title -->
    </div>
</aside>
<!-- /slider -->

Actually, 2 slider and slider-title blocks. Yes, these are the blocks. Because it's only part of the code.
And how to properly approach CSS styling:
Option 1:
<div class="slider-title">
    <h2>Натяжные потолки</h2>
    <h3>Установка качественных и долговечных потолков по отличным ценам</h3>
</div>
.slider-title {
    h2 {}
    h3 {}
}

or Option 2 would be correct:
<div class="slider-title">
    <h2 class="slider-title__h2">Натяжные потолки</h2>
    <h3 class="slider-title__h3">Установка качественных и долговечных потолков по отличным ценам</h3>
</div>
.slider-title {
    &__h2 {}
    &__h2 {}
}

That is, is it necessary to specify a class for h2 and h3, which will have only their own styles and will not be repeated anywhere?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Edward, 2016-10-22
@webirus

The second option is correct.
According to BEM, ideally, there should be no selectors, only classes and a minimum of cascades.
How to work with CSS preprocessors and BEM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question