SlideShare ist ein Scribd-Unternehmen logo
1 von 62
Downloaden Sie, um offline zu lesen
BEM it! 
Introduction to BEM Methodology 
by Varya Stepanova 
at SC5 Tuesday Streaming, 21.10.2014
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 
.button 
.text-field 
.flyout 
.heading 
.menu 
or with prefix 
.b-button 
.b-text-field 
.b-flyout 
.b-heading 
.b-menu
CSS naming conventions 
<ul class=”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 
.button__icon 
.text-field__label 
.flyout__title 
.heading__logo 
.menu__item
CSS naming conventions 
<ul class=”menu”> 
<li class=”menu__item”> 
<a href=”/more”>Read More</a> 
</li> 
<li class=”menu__item”> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li class=”menu__item”> 
<a href=”/buy”>Contact</a> 
</li> 
</ul>
CSS naming conventions 
MODIFIER 
.button_theme_dark 
.text-field_editable 
.flyout_align_top 
.heading_level_alpha 
.menu__item_promo
CSS naming conventions 
MODIFIER 
as you wish 
.button--theme--dark 
.text-field--editable 
.flyout--align--top 
.heading--level--alpha 
.menu__item--promo
CSS naming conventions 
<ul class=”menu”> 
<li class=”menu__item”> 
<a href=”/more”>Read More</a> 
</li> 
<li class=”menu__item”> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li class=”menu__item”> 
<a href=”/buy”>Contact</a> 
</li> 
</ul>
CSS naming conventions 
<ul class=”menu”> 
<li class=”menu__item menu__item_promo”> 
<a href=”/more”>Read More</a> 
</li> 
<li class=”menu__item”> 
<a href=”/buy”>Buy Online</a> 
</li> 
<li class=”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 global CSS resets
Benefits! 
Drop tag names and IDs 
● Faster selectors 
● Re-use same semantics on any tag: 
— <DIV class=”block”> 
— <SPAN class=”block”> 
— <TABLE class=”block”>
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! 
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?! 
...well, not exactly. 
Example of an element affected by a block modifier: 
/* theme menu items for a dark theme */ 
.menu_theme_dark .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 
.header .input { font-size: 0.85em } 
.header .button { background: navy }
Download Help Contact 
password LLooggiinn 
Main 
username 
.header .input { font-size: 0.85em } 
.header .button { background: navy } !
HOWTO: JavaScript
JavaScript 
Components → Blocks 
Work with BEM tree, not DOM tree
JavaScript deals with BEM 
blockObj 
blockObj.setMod('active'); 
// <div class=”block block_active”> 
blockObj.delMod('active); 
// <div class=”block”>
JavaScript deals with BEM 
BlockObj.do({ 
'active': function() { 
// do smth when active 
}, 
'disabled': function() { 
// do something when disabled 
} 
});
JavaScript 
i-bem.js framework by Yandex + tutorial 
http://bit.ly/bem-js-tutorial/ 
● First English 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: 
/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
Bundles for browsers 
page.css: 
@import url(“header/header.css”); 
@import url(“button/button.css”); 
@import url(“button/button_promo.css”); 
page.js: 
/* include: button.js */ 
/* include: login.js */
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
Build process and deployment 
Any familiar tool can be a builder 
Gulp: 
Example: 
https://github.com/getbem/getbem.com
BEM gives answers to: 
1. Where is code for this interface object? 
●CSS 
● JS 
●Templates 
●Documentation 
2.Can I remove this piece of code? 
3.How do I name this new item?
http://bem.info 
http://getbem.com
Thank you SC5! 
@varya_en 
http://varya.me

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
 
Bootstrap Part - 1
Bootstrap Part - 1Bootstrap Part - 1
Bootstrap Part - 1
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobile
 
Bootstrap ppt
Bootstrap pptBootstrap ppt
Bootstrap ppt
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
Css
CssCss
Css
 
CSS Grid
CSS GridCSS Grid
CSS Grid
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
jQuery
jQueryjQuery
jQuery
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
 
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by StepBootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
 
Introduction to flexbox
Introduction  to  flexboxIntroduction  to  flexbox
Introduction to flexbox
 

Andere mochten auch

Instrukacja montazu-listwy-sztywne-orac
Instrukacja montazu-listwy-sztywne-oracInstrukacja montazu-listwy-sztywne-orac
Instrukacja montazu-listwy-sztywne-orac
skleporac
 
An approach for managing and semantically enriching the publication of Linked...
An approach for managing and semantically enriching the publication of Linked...An approach for managing and semantically enriching the publication of Linked...
An approach for managing and semantically enriching the publication of Linked...
greco_ufrj
 
Presentation final
Presentation finalPresentation final
Presentation final
lyonka02
 
3 examen et corrige arabe 2014 1 am t1
3 examen et corrige arabe 2014 1 am t13 examen et corrige arabe 2014 1 am t1
3 examen et corrige arabe 2014 1 am t1
Ahmed Mesellem
 
1 examen et corrige edu civ 2014 1-am t1
1 examen et corrige edu civ 2014 1-am t11 examen et corrige edu civ 2014 1-am t1
1 examen et corrige edu civ 2014 1-am t1
Ahmed Mesellem
 
A3 examen et corrige francais 2011 1 am t2
A3 examen et corrige francais 2011 1 am t2A3 examen et corrige francais 2011 1 am t2
A3 examen et corrige francais 2011 1 am t2
Ahmed Mesellem
 
A4 examen et corrige arabe 2013 1 am t2
A4 examen et corrige arabe 2013 1 am t2A4 examen et corrige arabe 2013 1 am t2
A4 examen et corrige arabe 2013 1 am t2
Ahmed Mesellem
 

Andere mochten auch (20)

Instrukacja montazu-listwy-sztywne-orac
Instrukacja montazu-listwy-sztywne-oracInstrukacja montazu-listwy-sztywne-orac
Instrukacja montazu-listwy-sztywne-orac
 
Session 2 - Q&A
Session 2 - Q&ASession 2 - Q&A
Session 2 - Q&A
 
Du vil vel ikke mamma noe vondt?
Du vil vel ikke mamma noe vondt?Du vil vel ikke mamma noe vondt?
Du vil vel ikke mamma noe vondt?
 
Tic
TicTic
Tic
 
Presa itog 3
Presa itog 3Presa itog 3
Presa itog 3
 
Who am I?
Who am I?Who am I?
Who am I?
 
Dr. death
Dr. deathDr. death
Dr. death
 
Podstawy projektowania do Internetu - zdjęcia
Podstawy projektowania do Internetu - zdjęciaPodstawy projektowania do Internetu - zdjęcia
Podstawy projektowania do Internetu - zdjęcia
 
An approach for managing and semantically enriching the publication of Linked...
An approach for managing and semantically enriching the publication of Linked...An approach for managing and semantically enriching the publication of Linked...
An approach for managing and semantically enriching the publication of Linked...
 
Pemanfaatan ekstrak serai(sitronela) sebagai pengusir nyamuk
Pemanfaatan ekstrak serai(sitronela) sebagai pengusir nyamukPemanfaatan ekstrak serai(sitronela) sebagai pengusir nyamuk
Pemanfaatan ekstrak serai(sitronela) sebagai pengusir nyamuk
 
DOC3 - Soft Drinks and Beer 4 MI
DOC3 - Soft Drinks and Beer 4 MIDOC3 - Soft Drinks and Beer 4 MI
DOC3 - Soft Drinks and Beer 4 MI
 
Dia-logic
Dia-logicDia-logic
Dia-logic
 
Presentation final
Presentation finalPresentation final
Presentation final
 
UCE ESCUELA DE IDIOMAS "PREPOSITIONS OF PLACE" KEVIN QUEVEDO
UCE ESCUELA DE IDIOMAS "PREPOSITIONS OF PLACE" KEVIN QUEVEDO UCE ESCUELA DE IDIOMAS "PREPOSITIONS OF PLACE" KEVIN QUEVEDO
UCE ESCUELA DE IDIOMAS "PREPOSITIONS OF PLACE" KEVIN QUEVEDO
 
Horario Escolar - Profesores de Computo
Horario Escolar - Profesores de ComputoHorario Escolar - Profesores de Computo
Horario Escolar - Profesores de Computo
 
3 examen et corrige arabe 2014 1 am t1
3 examen et corrige arabe 2014 1 am t13 examen et corrige arabe 2014 1 am t1
3 examen et corrige arabe 2014 1 am t1
 
1 examen et corrige edu civ 2014 1-am t1
1 examen et corrige edu civ 2014 1-am t11 examen et corrige edu civ 2014 1-am t1
1 examen et corrige edu civ 2014 1-am t1
 
A3 examen et corrige francais 2011 1 am t2
A3 examen et corrige francais 2011 1 am t2A3 examen et corrige francais 2011 1 am t2
A3 examen et corrige francais 2011 1 am t2
 
A4 examen et corrige arabe 2013 1 am t2
A4 examen et corrige arabe 2013 1 am t2A4 examen et corrige arabe 2013 1 am t2
A4 examen et corrige arabe 2013 1 am t2
 
Binder1
Binder1Binder1
Binder1
 

Ähnlich wie BEM it! Introduction to BEM

Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater
 

Ähnlich wie BEM it! Introduction to BEM (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
 
BEM it!
BEM it!BEM it!
BEM it!
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
 
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
 
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
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
 
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
 
Html.ppt
Html.pptHtml.ppt
Html.ppt
 
Making Your Site Look Great in IE7
Making Your Site Look Great in IE7Making Your Site Look Great in IE7
Making Your Site Look Great in IE7
 
Flatsome | Responsive WooCommerce Theme - WordPress
Flatsome | Responsive WooCommerce Theme - WordPressFlatsome | Responsive WooCommerce Theme - WordPress
Flatsome | Responsive WooCommerce Theme - WordPress
 
Magento - Design Integration Guideline - Bysoft China
Magento - Design Integration Guideline - Bysoft ChinaMagento - Design Integration Guideline - Bysoft China
Magento - Design Integration Guideline - Bysoft China
 
BEM
BEMBEM
BEM
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
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
 
Introduction to the Magento eCommerce Platform
Introduction to the Magento eCommerce PlatformIntroduction to the Magento eCommerce Platform
Introduction to the Magento eCommerce Platform
 

Mehr von Varya Stepanova

SC5 Style Guide Generator
SC5 Style Guide GeneratorSC5 Style Guide Generator
SC5 Style Guide Generator
Varya Stepanova
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
Varya Stepanova
 

Mehr von Varya Stepanova (11)

Design systems on the web
Design systems on the webDesign systems on the web
Design systems on the web
 
SC5 Style Guide Generator
SC5 Style Guide GeneratorSC5 Style Guide Generator
SC5 Style Guide Generator
 
The Thinking behind BEM
The Thinking behind BEMThe Thinking behind BEM
The Thinking behind BEM
 
Modular development
Modular developmentModular development
Modular development
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
 
BEM. What you can borrow from Yandex frontend dev
BEM. What you can borrow from Yandex frontend devBEM. What you can borrow from Yandex frontend dev
BEM. What you can borrow from Yandex frontend dev
 
Тема для WordPress в БЭМ
Тема для WordPress в БЭМТема для WordPress в БЭМ
Тема для WordPress в БЭМ
 
Шаблонизатор BEMHTML
Шаблонизатор BEMHTMLШаблонизатор BEMHTML
Шаблонизатор BEMHTML
 
Использование библиотеки bem-bl
Использование библиотеки bem-blИспользование библиотеки bem-bl
Использование библиотеки bem-bl
 
JavaScript в БЭМ терминах
JavaScript в БЭМ терминахJavaScript в БЭМ терминах
JavaScript в БЭМ терминах
 
Использование библиотеки bem-bl
Использование библиотеки bem-blИспользование библиотеки bem-bl
Использование библиотеки bem-bl
 

Kürzlich hochgeladen

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Kürzlich hochgeladen (20)

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

BEM it! Introduction to BEM

  • 1. BEM it! Introduction to BEM Methodology by Varya Stepanova at SC5 Tuesday Streaming, 21.10.2014
  • 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 .button .text-field .flyout .heading .menu or with prefix .b-button .b-text-field .b-flyout .b-heading .b-menu
  • 24. CSS naming conventions <ul class=”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 .button__icon .text-field__label .flyout__title .heading__logo .menu__item
  • 26. CSS naming conventions <ul class=”menu”> <li class=”menu__item”> <a href=”/more”>Read More</a> </li> <li class=”menu__item”> <a href=”/buy”>Buy Online</a> </li> <li class=”menu__item”> <a href=”/buy”>Contact</a> </li> </ul>
  • 27. CSS naming conventions MODIFIER .button_theme_dark .text-field_editable .flyout_align_top .heading_level_alpha .menu__item_promo
  • 28. CSS naming conventions MODIFIER as you wish .button--theme--dark .text-field--editable .flyout--align--top .heading--level--alpha .menu__item--promo
  • 29. CSS naming conventions <ul class=”menu”> <li class=”menu__item”> <a href=”/more”>Read More</a> </li> <li class=”menu__item”> <a href=”/buy”>Buy Online</a> </li> <li class=”menu__item”> <a href=”/buy”>Contact</a> </li> </ul>
  • 30. CSS naming conventions <ul class=”menu”> <li class=”menu__item menu__item_promo”> <a href=”/more”>Read More</a> </li> <li class=”menu__item”> <a href=”/buy”>Buy Online</a> </li> <li class=”menu__item”> <a href=”/buy”>Contact</a> </li> </ul>
  • 31. so structure much much semantics wow very code such frontend
  • 32. BEM CSS: best practices 1. Map the whole document to BEM blocks 2. No CSS outside of blocks 3. Independent blocks → no global CSS resets
  • 33. Benefits! Drop tag names and IDs ● Faster selectors ● Re-use same semantics on any tag: — <DIV class=”block”> — <SPAN class=”block”> — <TABLE class=”block”>
  • 34. 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?
  • 35. 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>
  • 36. 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>
  • 37. Benefits! Bye-bye CSS cascade?! ...well, not exactly. Example of an element affected by a block modifier: /* theme menu items for a dark theme */ .menu_theme_dark .menu__item { color: white; background-color: darkgray; }
  • 39. Download Help Contact password LLooggiinn Main username
  • 40. mmeennuu Download Help Contact password LLooggiinn Main username hheeaaddeerr tteexxtt iinnppuutt tteexxtt iinnppuutt bbuuttttoonn
  • 41. Download Help Contact _size_small _size_small _primary password LLooggiinn Main username
  • 42. Download Help Contact password LLooggiinn Main username .header .input { font-size: 0.85em } .header .button { background: navy }
  • 43. Download Help Contact password LLooggiinn Main username .header .input { font-size: 0.85em } .header .button { background: navy } !
  • 45. JavaScript Components → Blocks Work with BEM tree, not DOM tree
  • 46. JavaScript deals with BEM blockObj blockObj.setMod('active'); // <div class=”block block_active”> blockObj.delMod('active); // <div class=”block”>
  • 47. JavaScript deals with BEM BlockObj.do({ 'active': function() { // do smth when active }, 'disabled': function() { // do something when disabled } });
  • 48. JavaScript i-bem.js framework by Yandex + tutorial http://bit.ly/bem-js-tutorial/ ● First English 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: /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. Bundles for browsers page.css: @import url(“header/header.css”); @import url(“button/button.css”); @import url(“button/button_promo.css”); page.js: /* include: button.js */ /* include: login.js */
  • 58. 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
  • 59. Build process and deployment Any familiar tool can be a builder Gulp: Example: https://github.com/getbem/getbem.com
  • 60. BEM gives answers to: 1. Where is code for this interface object? ●CSS ● JS ●Templates ●Documentation 2.Can I remove this piece of code? 3.How do I name this new item?
  • 62. Thank you SC5! @varya_en http://varya.me