Top Banner
BEM it! Martin Pešout / front-end developer at dotBlue @martinpesout
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: BEM it!

BEM it!

Martin Pešout / front-end developer at dotBlue @martinpesout

Page 2: BEM it!
Page 3: BEM it!

What is BEM?WHAT + WHY + HOW

Page 4: BEM it!

Milestone 2013• 2013

• boom of responsive design (RWD)

• RWD means also more complex CSS styles

Page 5: BEM it!

Milestone 2013• 2013

• boom of responsive design (RWD)

• RWD means also more complex CSS styles

• 2014

• boom of optimization of developed responsive webpages

• Fluid web doesn’t mean fast web on mobile connection

Page 6: BEM it!

Web development in 2014 needs methodology

We really need good rules !!

… rather than frameworks

Page 7: BEM it!

Why has been BEM created?

• The way how to organize code for whole team on big project

• Reusable components

• Long-standing components

• Easy to learn for new team members

Page 8: BEM it!

It’s not magicBEM is not hard to learn. A

lot of articles and examples everywhere.

Page 9: BEM it!

Don’t use #ID selectors!

Page 10: BEM it!

BEM = block + element + modifier

Page 11: BEM it!

Block• Standalone part of interface

• button

• menu

• heading

Page 12: BEM it!

Block• Standalone part of interface

• button

• menu

• heading

• Reusable

• Independent on other styles

Page 13: BEM it!

Element• An internal part of block

• button

• menu

• heading

Page 14: BEM it!

Element• An internal part of block

• button - icon

• menu - item

• heading - logo

Page 15: BEM it!

Element• An internal part of block

• button - icon

• menu - item

• heading - logo

• No standalone meaning outside of a block

• Some blocks have no element(s)

Page 16: BEM it!

Modifier• Defines the state of property on a block or

element

• button

• menu - item

• heading

Page 17: BEM it!

Modifier• Defines the state of property on a block or

element

• button - color

• menu - item - active state

• heading - level

Page 18: BEM it!

BEM uses class names to describe block, elements

and modifiers

Page 19: BEM it!

Naming convenctionblock btn menu heading

Page 20: BEM it!

Naming convenctionblock__element btn__icon menu__item heading__logo

Page 21: BEM it!

Naming convenctionblock__element––modifier btn––large btn__icon––arrow menu––secondary menu__item––active

Page 22: BEM it!
Page 23: BEM it!

Header<div class="header header--main"> <h1 class=“header__title">Brian &amp; Jessica</h1> <div class=“header__description”> Main information about our wedding </div> </div>

Page 24: BEM it!

Common mistakes

• Don’t use shared styles

• No common resets (only normalize.css is allowed)

• No CSS definition outside of block

<div class="header header--main"> <h1>Brian &amp; Jessica</h1> <p> Main information about our wedding </p> </div>

Page 25: BEM it!
Page 26: BEM it!

Button<a href="#love-story" class="action-btn action-btn––arrow-down”></a>

Page 27: BEM it!

Banner<div class=“banner"> <img src="/images/main-banner-large.jpg" alt="Bride and groom” class="banner__img"> <div class="banner__title">Soon together</div> <a href="#love-story" class="banner__btn action-btn action-btn--arrow-down"></a> </div>

Page 28: BEM it!

Banner<div class=“banner"> <img src="/images/main-banner-large.jpg" alt="Bride and groom” class="banner__img"> <div class="banner__title">Soon together</div> <a href="#love-story" class="banner__btn action-btn action-btn--arrow-down"></a> </div>

• We can combine more blocks together

Page 29: BEM it!

Independent styles• You can always change syntax and have always

the same look

<ul class=“menu”>

<li class=“menu__item”>Home</li>

<li class=“menu__item menu__item––active”>Contact</li>

</ul>

<div class=“menu”> <div class=“menu__item”>Home</div> <div class=“menu__item menu__item––active”>Contact</div> </div>

Page 30: BEM it!

Another best practices

• Preprocessor can help you to organize your styles to better file structure

• Use prefix js- class or ID prefix for JavaScript selectors

Page 31: BEM it!

Thank you

Martin Pešout / front-end developer at dotBlue @martinpesout