Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BEM

 BEM

Talk about Block, Elements and Modifiers.

Felipe Luiz Soares

October 28, 2016
Tweet

More Decks by Felipe Luiz Soares

Other Decks in Technology

Transcript

  1. Bem is Is a component-based approach to web development. The

    idea behind it is to divide the user interface into independent blocks. Understand the relationship between the HTML and CSS in a given project.
  2. Blocks A functionally independent page component that can be reused.

    In HTML, blocks are represented by the class attribute.
  3. Blocks can be nested in each other. You can have

    any number of nesting levels. Blocks
  4. Elements The element name describes its purpose ("What is this?"

    — item, text, etc.) The structure of an element's full name is block-name__element-name.
  5. Elements can be nested inside each other. You can have

    any number of nesting levels. Elements An element is always part of a block, not another element.
  6. Modifiers The modifier name describes its appearance ("What size?" or

    "Which theme?" and so on — theme_islands), state ("How is it different from the others?" — disabled, focused), behavior ("How does it behave?" or "How does it respond to the user?" — such as directions_left-top).
  7. From the BEM perspective, a modifier can't be used in

    isolation from the modified block or element. Modifiers A modifier should change the appearance, behavior, or state of the entity, not replace it.
  8. If a section of code might be reused and it

    doesn't depend on other page components being implemented, you should create a block.
  9. If the section of code can't be used separately without

    the parent entity (the block), an element is usually created.
  10. .search-form { background-color: red; &__button { margin: 20px; &--disabled {

    display: none; } } } .form { display: flex; &--focused { color: black; } }