D
D
Dmitry Lokshin2017-10-20 17:36:31
css
Dmitry Lokshin, 2017-10-20 17:36:31

Is such nesting of BEM selectors acceptable?

Hello!
I apologize for such an easy question, but something is a little confused.
I have this html structure:

<header class="header">
     <div class="locator header__locator">
          <span class="locator__text">Some text</span>
     </div>
</header>

Accordingly, header and locator are two independent blocks.
The locator_text has its own styles, but in the context of using the header block, I want to set specific styles for it, which creates a cascade, is this the right solution:
.locator {
     position: relative;
}

.locator__text {
     font-size: 18px;
     font-weight: bold;
}

.header__locator .locator__input {
     color: red;
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
tema_sun, 2017-10-20
@tema_sun

As for me, this is not the case when a cascade is needed. I'm for the modifier.

Q
quramolt, 2017-10-20
@quramolt

https://ru.bem.info/methodology/css - for that matter, BEM has become less strict and now even cascade is allowed there.
But I would make some kind of in-header modifier, because I would quickly remember what I meant.
https://ru.bem.info/methodology/block-modification/ - and here are the answers to your question.

4
4mobile, 2017-10-20
@4mobile

i would write like this

<header class="header">
     <div class="locator locator_header">
          <span class="locator__text">Some text</span>
     </div>
</header>

or so
<header class="header">
     <div class="locator">
          <span class="locator__text locator__text_header">Some text</span>
     </div>
</header>

S
skepsikmod, 2017-10-20
@skepsikmod

Extremely correct markup.
As an option, do not mix blocks, but nest a block in an element, but this is for an amateur and according to the situation.
But the styles are not quite correct. Dislikes BEM cascades.
At least formally, the parent may know about his offspring.
However, again, it all depends on the situation. Somewhere, in real examples, it is easier to set a modifier, somewhere to modify through a parent.
The question of understanding the appropriateness of using a particular combination.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question