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.
Generally, block-level elements may contain inline elements and (sometimes) other block-level elements.
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.
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.
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.
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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With