Skip to content

Instantly share code, notes, and snippets.

@luisrudge
Created May 15, 2015 23:13
Show Gist options
  • Save luisrudge/e3752737755b8d33ec4f to your computer and use it in GitHub Desktop.
Save luisrudge/e3752737755b8d33ec4f to your computer and use it in GitHub Desktop.
is this right according to BEM?
<aside class="sidebar">
<nav class="menu">
<div class="menu-item">
<a href="" class="menu-item__link">
<span class="menu-item__icon">
<i class="ion-ios-home-outline"></i>
</span>
<span class="menu-item__text">
Home
</span>
</a>
</div>
</nav>
</aside>
@bensmithett
Copy link

I'd tweak it a little bit...

<aside class="sidebar">

  <!-- 
    These two (likely) have a parent/child relationship
    A `menu` is a list of `menu__item` elements.
    A `menu__item` is just a container for whatever you choose to put inside.

    So the `menu` block is responsible for laying out your menu.
  -->
  <nav class="menu">
    <div class="menu__item">


      <!--
        `menu-link` is where you visually style individual links.
        It's got two child elements: `menu-link__icon` and `menu-link__text`.
      -->
      <a href="" class="menu-link">
        <span class="menu-link__icon">
          <i class="ion-ios-home-outline"></i>
        </span>
        <span class="menu-link__text">
          Home
        </span>
      </a>


    </div>
  </nav>
</aside>

@luisrudge
Copy link
Author

so I can go from an element (menu__item) to a block again (menu-link)?

@bensmithett
Copy link

@luisrudge absolutely, you just want to keep any nested blocks independent of their parents (i.e. reduce the depth of applicability). So you don't want styles from the menu block leaking through to menu-item.

@luisrudge
Copy link
Author

awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment