Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Elements contain Blocks in bem

Tags:

html

css

bem

oocss

I have been told I was wrong for writing the code like I have below. I suppose elements can not contain blocks and its bad b.e.m.

<ul class="b-nav">

    <li class="b-nav__item">

         <a href="#" class="b-nav__item__link"> Item </a>


     </li>

 </ul>

I thought about writing it this way but it doesn't show the hierarchy as well.

<ul class="b-nav">

    <li class="b-nav__item">

         <a href="#" class="b-nav__link"> Item </a>


     </li>

 </ul>

Here is another way but to me it seems worse than the example above.

<ul class="b-nav">

    <li class="b-nav__item">

         <a href="#" class="b-link"> Item </a>


     </li>

 </ul>

Is the way I originally coded it wrong? If so why, and what is the best alternative.

like image 613
Eric Harms Avatar asked Apr 09 '13 14:04

Eric Harms


People also ask

Can block elements contain block elements?

Generally, block-level elements may contain inline elements and (sometimes) other block-level elements.

What is block in BEM?

A BEM class name includes up to three parts. Block: The outermost parent element of the component is defined as the block. Element: Inside of the component may be one or more children called elements.

What are the elements in a block?

Two commonly used block elements are: <p> and <div> . The <p> element defines a paragraph in an HTML document. The <div> element defines a division or a section in an HTML document. The <p> element is a block-level element.

Why to use the block element modifier?

BEM stands for Block Element Modifier. The main idea behind it is to speed up the development process, and ease the teamwork of developers by arranging CSS classes into independent modules. If you ever saw a class name like header__form--search , that is BEM in action.


2 Answers

You should use second or third samples.

Or you could use this one (it uses BEM mixes; we have a talk on this in Russian). It is helpful then you need to access link elem of b-nav from javascript code.

<ul class="b-nav">

    <li class="b-nav__item">

         <a href="#" class="b-nav__link b-link"> Item </a>

     </li>

 </ul>
like image 163
Arikon Avatar answered Nov 15 '22 18:11

Arikon


I think naming it nav_link is more accepted than nav_item__link, even if a link belongs to an item. Maybe what I was doing was overkill to show that hierarchy. In the end, both belong to the same block.

I saw some examples in the comments of each link below

https://github.com/csswizardry/inuit.css/issues/155

http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/

like image 38
Eric Harms Avatar answered Nov 15 '22 19:11

Eric Harms