SlideShare uma empresa Scribd logo
1 de 60
Baixar para ler offline
BEM it! 
Introduction to BEM Methodology 
by Max Shirshin 
Frontend Team Lead, Deltamethod 
Consultant, Yandex
Why bother?
There is no unified semantic model 
across different FE technologies 
● HTML stands for hypertext 
I've heard we mostly do web apps... 
● CSS offers no structure out of the box 
Usually a pile of rules put together. Sorry. 
● JavaScript uses its own approaches. 
...a new one comes with every framework.
Frameworks are not enough 
● ≈ 8,500 packages in Bower registry 
● JavaScript: 
the most popular language on GitHub 
Repositories created: 
≈ 264,000 in 2013 
≈ 296,000 in 2012
BEM to the rescue
What is BEM? 
BEM claims that simple semantic model 
(Blocks, Elements, and Modifiers) 
is enough to define the way you author 
HTML / CSS / JavaScript, structure code 
and components, set up interaction 
and scale your project to build 
an industry-leading service.
What is BEM? 
● BEM is a methodology, not a framework 
Semantic model + best practices 
for all things frontend 
● BEM is a fix for web app semantics 
...the same as jQuery is a fix for DOM APIs 
● Originally introduced by Yandex 
— 19 million daily audience 
— 200+ web services 
— tools, code, tutorials, conferences 
— open source
Some theory
What is BEM? 
BLOCK 
– Standalone part of an interface: 
● button 
● text field 
● flyout 
● heading 
● menu
What is BEM? 
BLOCK 
– Standalone part of an interface: 
● button 
● text field 
● flyout 
● heading 
● menu 
– Re-usable in different contexts 
– Self-sufficient
What is BEM? 
ELEMENT 
– An integral part of a block: 
● button 
● text field 
● flyout 
● heading 
● menu
What is BEM? 
ELEMENT 
– An integral part of a block: 
● button — contains no elements 
● text field label 
● flyout title 
● heading logo 
● menu item
What is BEM? 
ELEMENT 
– An integral part of a block: 
● button — contains no elements 
● text field label 
● flyout title 
● heading logo 
● menu item 
– No standalone meaning outside of a block 
– Some blocks have no elements
What is BEM? 
MODIFIER 
– Defines property or state on a block or element: 
● button 
● text field 
● flyout 
● heading 
● menu item
What is BEM? 
MODIFIER 
– Defines property or state on a block or element: 
● button theme 
● text field editable state 
● flyout alignment 
● heading level 
● menu item bullet type
What is BEM? 
MODIFIER 
– Defines property or state on a block or element: 
● button theme 
● text field editable state 
● flyout alignment 
● heading level 
● menu item bullet type 
– Multiple modifiers may co-exist 
on a single block/element
BEM forms a semantic overlay over the 
existing DOM structure. 
This overlay is called a BEM tree.
DOM tree → BEM tree
How does BEM map to DOM? 
● Blocks/elems/mods are denoted 
with CSS classes using a naming convention. 
● DOM nodes can be shared: 
— block1 + block2 may occupy the same 
container; 
— element1 + block2 may co-exist on 
the same node. 
● DOM is encapsulated: 
— complex DOM structure may constitute 
a single element
BEM HOWTO 
for your beloved project 
with benefits explained
HOWTO: HTML / CSS
CSS naming conventions 
“BEM uses CSS class names to denote 
blocks, elements and modifiers.”
CSS naming conventions 
BLOCK 
.b-button 
.b-text-field 
.b-flyout 
.b-heading 
.b-menu
CSS naming conventions 
<ul class=”b-menu”> 
<li> 
<a href=”/more”>Read More</a> 
</li> 
<li> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li> 
<a href=”/buy”>Contact</a> 
</li> 
</ul>
CSS naming conventions 
ELEMENT 
.b-button__icon 
.b-text-field__label 
.b-flyout__title 
.b-heading__logo 
.b-menu__item
CSS naming conventions 
<ul class=”b-menu”> 
<li class=”b-menu__item”> 
<a href=”/more”>Read More</a> 
</li> 
<li class=”b-menu__item”> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li class=”b-menu__item”> 
<a href=”/buy”>Contact</a> 
</li> 
</ul>
CSS naming conventions 
MODIFIER 
.b-button_theme_dark 
.b-text-field_editable 
.b-flyout_align_top 
.b-heading_level_alpha 
.b-menu__item_promo
CSS naming conventions 
<ul class=”b-menu”> 
<li class=”b-menu__item”> 
<a href=”/more”>Read More</a> 
</li> 
<li class=”b-menu__item”> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li class=”b-menu__item”> 
<a href=”/buy”>Contact</a> 
</li> 
</ul>
CSS naming conventions 
<ul class=”b-menu”> 
<li class=”b-menu__item b-menu__item_promo”> 
<a href=”/more”>Read More</a> 
</li> 
<li class=”b-menu__item”> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li class=”b-menu__item”> 
<a href=”/buy”>Contact</a> 
</li> 
</ul>
so structure 
much much semantics 
wow 
very code 
such frontend
BEM CSS: best practices 
1. Map the whole document to BEM blocks 
2. No CSS outside of blocks 
3. Independent blocks → no CSS resets
Benefits! 
Drop tag names and IDs 
● Faster selectors 
● Re-use same semantics on any tag: 
— <DIV class=”b-block”> 
— <SPAN class=”b-block”> 
— <TABLE class=”b-block”>
Benefits! 
CSS specificity magic solved 
Priority of CSS rules: 
by specificity first, then by rule order 
td.data { background-color: gray } 
td.summary { background-color: white } 
.total-summary { background-color: yellow } 
<TD class="summary total-summary"> 
<!-- Still gray, baby :-( --> 
</TD>
Benefits! 
CSS specificity magic solved 
Priority of CSS rules: 
by specificity first, then by rule order 
td.data { background-color: gray } 
td.summary { background-color: white } 
td.total-summary { background-color: yellow } 
<TD class="summary total-summary"> 
<!-- This works, I'm yellow now --> 
</TD>
Benefits! 
Bye-bye CSS cascade?! 
Only one CSS class needed to: 
● style a block container 
● style any element within a block 
● add extras/overrides with a modifier 
Doesn't it cover 90% of your styling needs?
Benefits! 
Bye-bye CSS cascade?! 
...well, not exactly. 
Example of an element affected by a block modifier: 
/* theme menu items for a dark theme */ 
.b-menu_theme_dark .b-menu__item 
{ 
color: white; 
background-color: darkgray; 
}
HOWTO: 
Block dependencies
Download Help Contact 
password LLooggiinn 
Main 
username
mmeennuu 
Download Help Contact 
password LLooggiinn 
Main 
username 
hheeaaddeerr 
tteexxtt iinnppuutt tteexxtt iinnppuutt bbuuttttoonn
Download Help Contact 
_size_small _size_small _primary 
password LLooggiinn 
Main 
username
Download Help Contact 
password LLooggiinn 
Main 
username 
.b-header .b-input { font-size: 0.85em } 
.b-header .b-button { background: navy }
Download Help Contact 
password LLooggiinn 
Main 
username 
.b-header .b-input { font-size: 0.85em } 
.b-header .b-button { background: navy } !
HOWTO: JavaScript
JavaScript 
Components → Blocks 
Work with BEM tree, not DOM tree
JavaScript 
jQuery BEM helpers 
https://github.com/ingdir/jquery-bemhelpers 
● Helper methods to work with BEM modifiers 
● Callbacks on modifiers set/change
JavaScript 
jQuery BEM helpers 
// find a block with jQuery selectors 
var $block = component.find('div'); 
// assign a callback to a modifier change 
$block.onSetMod('b-block', { 
status: { 
loaded: myCallback 
} 
}); 
/* ... */ 
$block.setMod('b-block', 'status', 'loaded'); 
// 1. adds a CSS class b-block_status_loaded 
// 2. runs myCallback()
JavaScript 
jQuery BEM plugin 
http://xslc.org/jquery-bem/ 
● Extends jQuery Sizzle with selectors for BEM 
entities (mix them with “normal” selectors) 
● Add callbacks on modifiers set/change 
● Supports methods tied to blocks/elements
JavaScript 
i-bem.js framework by Yandex + tutorial 
https://github.com/toivonen/bem-js-tutorial 
● First English draft docs (expect more!) 
● 100% BEM-based declarative API 
● Part of a larger bem-core library
HTML is no longer semantic. 
JavaScript is.
HOWTO: Design / UX
BEM is the universal language 
for developers and designers, 
the bridge across technology gaps.
Build your block library. 
The code itself is the styleguide.
UX + Frontend 
● Live style guide 
● Always up-to-date 
● Prototyping mapped to code from day one 
● Designers and devs speak the same 
language 
● Good for making early estimates
HOWTO: File structure
File and folder structure 
Flat block structure with a folder for each block. 
Simple structure for BEM beginners: 
/b-block 
block.css 
block.js 
block.tpl 
...whatever you need
File and folder structure 
Advanced structure to expose semantics 
/block 
/__elem1 
block__elem1.css 
block__elem1.tpl 
/_mod 
block_mod.css 
block.css 
block.js 
block.tpl
Redefinition Levels 
/common 
/block 
/__elem1 
block__elem1.css 
block__elem1.tpl 
/_mod 
block_mod.css 
block.css 
block.js 
block.tpl 
/my-page 
/block 
/__elem1 
block__elem1.css 
/_mod2 
block_mod2.css
Redefinition Levels 
/common 
/block 
/__elem1 
block__elem1.css 
block__elem1.tpl 
/_mod 
block_mod.css 
block.css 
block.js 
block.tpl 
/my-page 
/block 
/__elem1 
block__elem1.css 
/_mod2 
block_+ mod2.css
Build process and deployment 
Use a build tool! 
Borschik: 
an open-source build tool by Yandex 
Code: 
https://github.com/bem/borschik 
English docs: 
http://bem.info/articles/borschik
Thank you Brandwatch! 
max.shirshin@gmail.com google.com/+MaxShirshin 
@ingdir maxshirshin

Mais conteúdo relacionado

Mais procurados

CSS For Backend Developers
CSS For Backend DevelopersCSS For Backend Developers
CSS For Backend Developers10Clouds
 
OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?Michael Posso
 
What is Object Oriented CSS?
What is Object Oriented CSS?What is Object Oriented CSS?
What is Object Oriented CSS?Nicole Sullivan
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2EPAM Systems
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignZoe Gillenwater
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basicsEliran Eliassy
 
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Stephen Hay
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid LayoutRachel Andrew
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, cssAamir Sohail
 
Tailwind CSS - KanpurJS
Tailwind CSS - KanpurJSTailwind CSS - KanpurJS
Tailwind CSS - KanpurJSNaveen Kharwar
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designersSingsys Pte Ltd
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overviewJacob Nelson
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5IT Geeks
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSSMario Hernandez
 
CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)Woodridge Software
 

Mais procurados (20)

CSS For Backend Developers
CSS For Backend DevelopersCSS For Backend Developers
CSS For Backend Developers
 
OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?
 
What is Object Oriented CSS?
What is Object Oriented CSS?What is Object Oriented CSS?
What is Object Oriented CSS?
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
 
The Power of CSS Flexbox
The Power of CSS FlexboxThe Power of CSS Flexbox
The Power of CSS Flexbox
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
 
Tailwind CSS - KanpurJS
Tailwind CSS - KanpurJSTailwind CSS - KanpurJS
Tailwind CSS - KanpurJS
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
 
CSS
CSSCSS
CSS
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)
 
Flex box
Flex boxFlex box
Flex box
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSS
 

Semelhante a BEM It! for Brandwatch

Build and save your own Gutenberg Block Patterns
Build and save your own Gutenberg Block PatternsBuild and save your own Gutenberg Block Patterns
Build and save your own Gutenberg Block PatternsPlasterdog Web Design
 
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog TemplateBlog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog TemplateSean Burgess
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding StandardsSaajan Maharjan
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applicationsVittorio Vittori
 
Magento - Design Integration Guideline - Bysoft China
Magento - Design Integration Guideline - Bysoft ChinaMagento - Design Integration Guideline - Bysoft China
Magento - Design Integration Guideline - Bysoft ChinaBysoft Technologies
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with ReactImran Sayed
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSZoe Gillenwater
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSSanjoy Kr. Paul
 
Let's BEM together
Let's BEM togetherLet's BEM together
Let's BEM togetherAmit Gupta
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionIn a Rocket
 
Joomla! Day UK 2009 Basic Templates
Joomla! Day UK 2009 Basic TemplatesJoomla! Day UK 2009 Basic Templates
Joomla! Day UK 2009 Basic TemplatesAndy Wallace
 
Joomla Day UK 2009 Basic Templates
Joomla Day UK 2009 Basic TemplatesJoomla Day UK 2009 Basic Templates
Joomla Day UK 2009 Basic TemplatesChris Davenport
 
Front end workflow Presentation at Coffee@DBG by Praveen Vijayan
Front end workflow Presentation at Coffee@DBG by Praveen VijayanFront end workflow Presentation at Coffee@DBG by Praveen Vijayan
Front end workflow Presentation at Coffee@DBG by Praveen VijayanDeepu S Nath
 
Vision academy sachinsir_9822506209_html_java_script_notes (1)
Vision academy sachinsir_9822506209_html_java_script_notes (1)Vision academy sachinsir_9822506209_html_java_script_notes (1)
Vision academy sachinsir_9822506209_html_java_script_notes (1)ShraddhaGurav7
 

Semelhante a BEM It! for Brandwatch (20)

BEM it!
BEM it!BEM it!
BEM it!
 
BEM methodology overview
BEM methodology overviewBEM methodology overview
BEM methodology overview
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 
Build and save your own Gutenberg Block Patterns
Build and save your own Gutenberg Block PatternsBuild and save your own Gutenberg Block Patterns
Build and save your own Gutenberg Block Patterns
 
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog TemplateBlog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
 
BEM
BEMBEM
BEM
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
BEM it!
BEM it!BEM it!
BEM it!
 
Magento - Design Integration Guideline - Bysoft China
Magento - Design Integration Guideline - Bysoft ChinaMagento - Design Integration Guideline - Bysoft China
Magento - Design Integration Guideline - Bysoft China
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with React
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Let's BEM together
Let's BEM togetherLet's BEM together
Let's BEM together
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
Joomla! Day UK 2009 Basic Templates
Joomla! Day UK 2009 Basic TemplatesJoomla! Day UK 2009 Basic Templates
Joomla! Day UK 2009 Basic Templates
 
Joomla Day UK 2009 Basic Templates
Joomla Day UK 2009 Basic TemplatesJoomla Day UK 2009 Basic Templates
Joomla Day UK 2009 Basic Templates
 
Front end workflow Presentation at Coffee@DBG by Praveen Vijayan
Front end workflow Presentation at Coffee@DBG by Praveen VijayanFront end workflow Presentation at Coffee@DBG by Praveen Vijayan
Front end workflow Presentation at Coffee@DBG by Praveen Vijayan
 
Vision academy sachinsir_9822506209_html_java_script_notes (1)
Vision academy sachinsir_9822506209_html_java_script_notes (1)Vision academy sachinsir_9822506209_html_java_script_notes (1)
Vision academy sachinsir_9822506209_html_java_script_notes (1)
 

Último

Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiMonica Sydney
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查ydyuyu
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...meghakumariji156
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 

Último (20)

Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 

BEM It! for Brandwatch

  • 1. BEM it! Introduction to BEM Methodology by Max Shirshin Frontend Team Lead, Deltamethod Consultant, Yandex
  • 3. There is no unified semantic model across different FE technologies ● HTML stands for hypertext I've heard we mostly do web apps... ● CSS offers no structure out of the box Usually a pile of rules put together. Sorry. ● JavaScript uses its own approaches. ...a new one comes with every framework.
  • 4. Frameworks are not enough ● ≈ 8,500 packages in Bower registry ● JavaScript: the most popular language on GitHub Repositories created: ≈ 264,000 in 2013 ≈ 296,000 in 2012
  • 5. BEM to the rescue
  • 6. What is BEM? BEM claims that simple semantic model (Blocks, Elements, and Modifiers) is enough to define the way you author HTML / CSS / JavaScript, structure code and components, set up interaction and scale your project to build an industry-leading service.
  • 7. What is BEM? ● BEM is a methodology, not a framework Semantic model + best practices for all things frontend ● BEM is a fix for web app semantics ...the same as jQuery is a fix for DOM APIs ● Originally introduced by Yandex — 19 million daily audience — 200+ web services — tools, code, tutorials, conferences — open source
  • 9. What is BEM? BLOCK – Standalone part of an interface: ● button ● text field ● flyout ● heading ● menu
  • 10. What is BEM? BLOCK – Standalone part of an interface: ● button ● text field ● flyout ● heading ● menu – Re-usable in different contexts – Self-sufficient
  • 11. What is BEM? ELEMENT – An integral part of a block: ● button ● text field ● flyout ● heading ● menu
  • 12. What is BEM? ELEMENT – An integral part of a block: ● button — contains no elements ● text field label ● flyout title ● heading logo ● menu item
  • 13. What is BEM? ELEMENT – An integral part of a block: ● button — contains no elements ● text field label ● flyout title ● heading logo ● menu item – No standalone meaning outside of a block – Some blocks have no elements
  • 14. What is BEM? MODIFIER – Defines property or state on a block or element: ● button ● text field ● flyout ● heading ● menu item
  • 15. What is BEM? MODIFIER – Defines property or state on a block or element: ● button theme ● text field editable state ● flyout alignment ● heading level ● menu item bullet type
  • 16. What is BEM? MODIFIER – Defines property or state on a block or element: ● button theme ● text field editable state ● flyout alignment ● heading level ● menu item bullet type – Multiple modifiers may co-exist on a single block/element
  • 17. BEM forms a semantic overlay over the existing DOM structure. This overlay is called a BEM tree.
  • 18. DOM tree → BEM tree
  • 19. How does BEM map to DOM? ● Blocks/elems/mods are denoted with CSS classes using a naming convention. ● DOM nodes can be shared: — block1 + block2 may occupy the same container; — element1 + block2 may co-exist on the same node. ● DOM is encapsulated: — complex DOM structure may constitute a single element
  • 20. BEM HOWTO for your beloved project with benefits explained
  • 22. CSS naming conventions “BEM uses CSS class names to denote blocks, elements and modifiers.”
  • 23. CSS naming conventions BLOCK .b-button .b-text-field .b-flyout .b-heading .b-menu
  • 24. CSS naming conventions <ul class=”b-menu”> <li> <a href=”/more”>Read More</a> </li> <li> <a href=”/buy”>Buy Online</a> </li> <li> <a href=”/buy”>Contact</a> </li> </ul>
  • 25. CSS naming conventions ELEMENT .b-button__icon .b-text-field__label .b-flyout__title .b-heading__logo .b-menu__item
  • 26. CSS naming conventions <ul class=”b-menu”> <li class=”b-menu__item”> <a href=”/more”>Read More</a> </li> <li class=”b-menu__item”> <a href=”/buy”>Buy Online</a> </li> <li class=”b-menu__item”> <a href=”/buy”>Contact</a> </li> </ul>
  • 27. CSS naming conventions MODIFIER .b-button_theme_dark .b-text-field_editable .b-flyout_align_top .b-heading_level_alpha .b-menu__item_promo
  • 28. CSS naming conventions <ul class=”b-menu”> <li class=”b-menu__item”> <a href=”/more”>Read More</a> </li> <li class=”b-menu__item”> <a href=”/buy”>Buy Online</a> </li> <li class=”b-menu__item”> <a href=”/buy”>Contact</a> </li> </ul>
  • 29. CSS naming conventions <ul class=”b-menu”> <li class=”b-menu__item b-menu__item_promo”> <a href=”/more”>Read More</a> </li> <li class=”b-menu__item”> <a href=”/buy”>Buy Online</a> </li> <li class=”b-menu__item”> <a href=”/buy”>Contact</a> </li> </ul>
  • 30. so structure much much semantics wow very code such frontend
  • 31. BEM CSS: best practices 1. Map the whole document to BEM blocks 2. No CSS outside of blocks 3. Independent blocks → no CSS resets
  • 32. Benefits! Drop tag names and IDs ● Faster selectors ● Re-use same semantics on any tag: — <DIV class=”b-block”> — <SPAN class=”b-block”> — <TABLE class=”b-block”>
  • 33. Benefits! CSS specificity magic solved Priority of CSS rules: by specificity first, then by rule order td.data { background-color: gray } td.summary { background-color: white } .total-summary { background-color: yellow } <TD class="summary total-summary"> <!-- Still gray, baby :-( --> </TD>
  • 34. Benefits! CSS specificity magic solved Priority of CSS rules: by specificity first, then by rule order td.data { background-color: gray } td.summary { background-color: white } td.total-summary { background-color: yellow } <TD class="summary total-summary"> <!-- This works, I'm yellow now --> </TD>
  • 35. Benefits! Bye-bye CSS cascade?! Only one CSS class needed to: ● style a block container ● style any element within a block ● add extras/overrides with a modifier Doesn't it cover 90% of your styling needs?
  • 36. Benefits! Bye-bye CSS cascade?! ...well, not exactly. Example of an element affected by a block modifier: /* theme menu items for a dark theme */ .b-menu_theme_dark .b-menu__item { color: white; background-color: darkgray; }
  • 38. Download Help Contact password LLooggiinn Main username
  • 39. mmeennuu Download Help Contact password LLooggiinn Main username hheeaaddeerr tteexxtt iinnppuutt tteexxtt iinnppuutt bbuuttttoonn
  • 40. Download Help Contact _size_small _size_small _primary password LLooggiinn Main username
  • 41. Download Help Contact password LLooggiinn Main username .b-header .b-input { font-size: 0.85em } .b-header .b-button { background: navy }
  • 42. Download Help Contact password LLooggiinn Main username .b-header .b-input { font-size: 0.85em } .b-header .b-button { background: navy } !
  • 44. JavaScript Components → Blocks Work with BEM tree, not DOM tree
  • 45. JavaScript jQuery BEM helpers https://github.com/ingdir/jquery-bemhelpers ● Helper methods to work with BEM modifiers ● Callbacks on modifiers set/change
  • 46. JavaScript jQuery BEM helpers // find a block with jQuery selectors var $block = component.find('div'); // assign a callback to a modifier change $block.onSetMod('b-block', { status: { loaded: myCallback } }); /* ... */ $block.setMod('b-block', 'status', 'loaded'); // 1. adds a CSS class b-block_status_loaded // 2. runs myCallback()
  • 47. JavaScript jQuery BEM plugin http://xslc.org/jquery-bem/ ● Extends jQuery Sizzle with selectors for BEM entities (mix them with “normal” selectors) ● Add callbacks on modifiers set/change ● Supports methods tied to blocks/elements
  • 48. JavaScript i-bem.js framework by Yandex + tutorial https://github.com/toivonen/bem-js-tutorial ● First English draft docs (expect more!) ● 100% BEM-based declarative API ● Part of a larger bem-core library
  • 49. HTML is no longer semantic. JavaScript is.
  • 51. BEM is the universal language for developers and designers, the bridge across technology gaps.
  • 52. Build your block library. The code itself is the styleguide.
  • 53. UX + Frontend ● Live style guide ● Always up-to-date ● Prototyping mapped to code from day one ● Designers and devs speak the same language ● Good for making early estimates
  • 55. File and folder structure Flat block structure with a folder for each block. Simple structure for BEM beginners: /b-block block.css block.js block.tpl ...whatever you need
  • 56. File and folder structure Advanced structure to expose semantics /block /__elem1 block__elem1.css block__elem1.tpl /_mod block_mod.css block.css block.js block.tpl
  • 57. Redefinition Levels /common /block /__elem1 block__elem1.css block__elem1.tpl /_mod block_mod.css block.css block.js block.tpl /my-page /block /__elem1 block__elem1.css /_mod2 block_mod2.css
  • 58. Redefinition Levels /common /block /__elem1 block__elem1.css block__elem1.tpl /_mod block_mod.css block.css block.js block.tpl /my-page /block /__elem1 block__elem1.css /_mod2 block_+ mod2.css
  • 59. Build process and deployment Use a build tool! Borschik: an open-source build tool by Yandex Code: https://github.com/bem/borschik English docs: http://bem.info/articles/borschik
  • 60. Thank you Brandwatch! max.shirshin@gmail.com google.com/+MaxShirshin @ingdir maxshirshin