Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion with BEM class naming convention. One level deeper

For example I have a menu block with menu elements:

.menu
.menu__element
.menu__element--current

But lets say .menu block is contained inside another block, .header

How to deal with naming in this case?

.header 
.header__menu 
.header__element 

or

.header 
.header__menu 
.header__menu__element 

or

.header 
.menu 
.menu__element
like image 584
gskalinskii Avatar asked Mar 08 '13 12:03

gskalinskii


3 Answers

Consider using "mixes" (more than one BEM entity on the same DOM-node):

<div class="header">
    <ul class="menu header__menu">
        <li class="menu__element"></li>
        <!-- ... -->
    </ul>
</div>

So block menu is also element header__menu at the same time. That gives you the ability to apply styles for any abstract menu and add special rules for that particular menu inside the header.

like image 112
tadatuta Avatar answered Nov 10 '22 19:11

tadatuta


The menu should be a class unto itself so .menu should suffice. If it's a menu that is ONLY in a header and never anywhere else, then .header-menu. Then you can point to the menu directly without going through the header class.

If you prefer to do it the way you outlined, then .header_menu.

like image 25
Rob Avatar answered Nov 10 '22 18:11

Rob


<div class="header">
    <ul class="menu">
        <li class="menu__element">...</li>
        <li class="menu__element menu__element--current">...</li>
        ...
    </ul>
</div>    

.header {...}
.menu {...}
.menu__element {...}
.menu__element--current {...}

will be right.

Block name does not change when block inserted into another block.

BEM prohibits put an elements in the elements and write classnames like block__element__element, more info: How to properly set an element's scope using BEM?

like image 29
Ihor Zenich Avatar answered Nov 10 '22 19:11

Ihor Zenich