SlideShare ist ein Scribd-Unternehmen logo
1 von 69
Downloaden Sie, um offline zu lesen
by Max Shirshin
Frontend Team Lead, Deltamethod
Consultant, Yandex
BEM it!
BEM Methodology for small companies
with high expectations
Why bother?
Web development needs:
● Methodologies, not frameworks
● Same entities across different
technologies
● Scalability
BEM to the rescue
What is BEM?
“BEM claims that three basic entities
(Blocks, Elements, and Modifiers)
are 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?
● A methodology
“Theoretical underpinning” for methods and best
practices
What is BEM?
● A methodology
“Theoretical underpinning” for methods and best
practices
● Originally introduced by Yandex
— www.yandex.ru (English: www.yandex.com)
— 200+ Yandex services using full BEM stack
(methodology + tools)
— 19 million users daily audience
What is BEM?
● A methodology
“Theoretical underpinning” for methods and best
practices
● Originally introduced by Yandex
— www.yandex.ru (English: www.yandex.com)
— 200+ Yandex services using full BEM stack
(methodology + tools)
— 19 million users daily audience
● Used by external projects
— other services
— tools / libraries
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 icon
● text field label
● flyout title
● heading logo
● menu item
What is BEM?
ELEMENT
– An integral part of a block:
● button icon
● 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 color
● text field disabled state
● flyout alignment
● heading level
● menu item bullet type
What is BEM?
MODIFIER
– Defines property or state on a block or element:
● button color
● text field disabled state
● flyout alignment
● heading level
● menu item bullet type
– Multiple modifiers may co-exist
on a single block/element
BEM + DOM
● Blocks are mapped to DOM
BEM + DOM
● Blocks are mapped to DOM
● Blocks/elems/mods are denoted
with CSS classes
BEM + DOM
● Blocks are mapped to DOM
● Blocks/elems/mods are denoted
with CSS classes
● DOM nodes can be “shared”: you can mix
(block1 + block2) or (element1 + block2)
on a same node
BEM markup forms a semantic overlay
over the existing DOM structure.
This overlay is called a BEM tree.
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_color_blue
.b-text-field_disabled
.b-flyout_align_top
.b-heading_level_alpha
.b-menu__item_pos_first
CSS naming conventions
<ul class=”b-menu b-menu_horizontal”>
<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 b-menu_horizontal”>
<li class=”b-menu__item b-menu__item_pos_first”>
<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>
Additional notes on CSS
● Page (Document) is also a block
Additional notes on CSS
● Page (Document) is also a block
● Layouts are blocks (same rules apply)
Additional notes on CSS
● Page (Document) is also a block
● Layouts are blocks (same rules apply)
● No CSS outside of blocks
Additional notes on CSS
● Page (Document) is also a block
● Layouts are blocks (same rules apply)
● No CSS outside of blocks
● No common CSS resets (block independency!)
Additional notes on CSS
● Page (Document) is also a block
● Layouts are blocks (same rules apply)
● No CSS outside of blocks
● No common CSS resets (block independency!)
● No “shared” styles (no need)
Additional notes on CSS
● Page (Document) is also a block
● Layouts are blocks (same rules apply)
● No CSS outside of blocks
● No common CSS resets (block independency!)
● No “shared” styles (no need)
● DOM tree → BEM tree
Benefits!
Drop tag names and IDs
Benefits!
Drop tag names and IDs
● Faster selectors
● Re-use same semantic block on:
— <DIV class=”b-block”>
— <SPAN class=”b-block”>
— <TABLE class=”b-block”>
Benefits!
CSS specificity magic solved
Benefits!
CSS specificity magic solved
Priority of CSS rules:
by specificity first, then by rule order
Benefits!
CSS specificity magic solved
Priority of CSS rules:
by specificity first, then by rule order
td.odd { background-color: gray }
td.even { background-color: white }
.highlighted { background-color: yellow }
<TD class="odd highlighted">
<!-- Still gray, baby :-( -->
</TD>
Benefits!
CSS specificity magic solved
Priority of CSS rules:
by specificity first, then by rule order
td.odd { background-color: gray }
td.even { background-color: white }
td.highlighted { background-color: yellow }
<TD class="odd highlighted">
<!-- This works, I'm yellow now -->
</TD>
Benefits!
Bye-bye CSS cascade?!
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:
/* hide labels for disabled text fields */
.b-text-input_disabled .b-text-input__label
{
display: none;
}
HOWTO: JavaScript
JavaScript
Components → Blocks
Work with BEM tree, not DOM tree
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
JavaScript
Twitter Flight (used by Deltamethod)
http://flightjs.github.io
● Self-contained components, 100% event-driven
● Based on jQuery; AMD-friendly; BEM-friendly
● Built-in syntax sugar for predefined selectors
(good for BEM tree)
● [Shameless self-promo] Try Flight with Reggirt:
http://github.com/ingdir/reggirt
jQuery plugin that emulates event capturing
(opposite of event bubbling)
JavaScript
Twitter Flight (used by Deltamethod)
http://flightjs.github.io
● Self-contained components, 100% event-driven
● Based on jQuery; AMD-friendly; BEM-friendly
● Built-in syntax sugar for predefined selectors
(good for BEM tree)
● [Shameless self-promo] Try Flight with Reggirt:
http://github.com/ingdir/reggirt
jQuery plugin that emulates event capturing
(opposite of event bubbling)
Benefits!
HTML is no longer semantic.
JavaScript is.
HOWTO: Design / UX
BEM is the universal language
for developers and designers,
the bridge across technology gaps.
UX + Frontend
● Design a style guide
UX + Frontend
● Design a style guide
● Keep it up-to-date
UX + Frontend
● Design a style guide
● Keep it up-to-date, always!
UX + Frontend
● Design a style guide
● Keep it up-to-date, always!
● Build new screens quickly
UX + Frontend
Build your block library.
The code itself is the styleguide.
Benefits!
● Prototyping mapped to code from day 1
Benefits!
● Prototyping mapped to code from day 1
● Code mapped to prototypes from day 1
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
/css
block.css
block__elem1.css block__elem2.css
block_mod.css
/js
block.js
/template
block.tpl block__elem1.tpl block__elem2.tpl
File and folder structure
Advanced structure to expose semantics
/block
/css
block.css
block__elem1.css block__elem2.css
block_mod.css
/js
block.js
/template
block.tpl block__elem1.tpl block__elem2.tpl
Benefits!
● Unified structure for automation
● Redefinition levels: different libraries, same
structure
/common
/b-block
/css
block.css
/template
block.tpl
/app1
/b-block
/css
block__elem1.css
/js
block.js
/template
block__elem1.tpl
+
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
max.shirshin@gmail.com http://gplus.to/ingdir
@ingdir maxshirshin
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreRuss Weakley
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEMVarya Stepanova
 
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...Jer Clarke
 
Html & Css presentation
Html  & Css presentation Html  & Css presentation
Html & Css presentation joilrahat
 
Decoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSSDecoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSSJulie Cameron
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing worldRuss Weakley
 
CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong? CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong? Russ Weakley
 
OOCSS, SMACSS or BEM, what is the question...
OOCSS, SMACSS or BEM, what is the question...OOCSS, SMACSS or BEM, what is the question...
OOCSS, SMACSS or BEM, what is the question...Michael Posso
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTMLAmit Tyagi
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The FabulousNicole Sullivan
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3Doris Chen
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS MethodologyZohar Arad
 
Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5Russ Weakley
 
What is Object Oriented CSS?
What is Object Oriented CSS?What is Object Oriented CSS?
What is Object Oriented CSS?Nicole Sullivan
 

Was ist angesagt? (20)

CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
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 & Css presentation
Html  & Css presentation Html  & Css presentation
Html & Css presentation
 
Decoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSSDecoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSS
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing world
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong? CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong?
 
OOCSS, SMACSS or BEM, what is the question...
OOCSS, SMACSS or BEM, what is the question...OOCSS, SMACSS or BEM, what is the question...
OOCSS, SMACSS or BEM, what is the question...
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The Fabulous
 
What is Modular CSS?
What is Modular CSS?What is Modular CSS?
What is Modular CSS?
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Fundamental CSS3
Fundamental CSS3Fundamental CSS3
Fundamental CSS3
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
 
CSS3 Introduction
CSS3 IntroductionCSS3 Introduction
CSS3 Introduction
 
Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5
 
What is Object Oriented CSS?
What is Object Oriented CSS?What is Object Oriented CSS?
What is Object Oriented CSS?
 

Ähnlich wie BEM it!

BEM for Javascript at CampJS III
BEM for Javascript at CampJS IIIBEM for Javascript at CampJS III
BEM for Javascript at CampJS IIIYandex
 
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
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSZoe Gillenwater
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding StandardsSaajan Maharjan
 
Web technologies-course 02.pptx
Web technologies-course 02.pptxWeb technologies-course 02.pptx
Web technologies-course 02.pptxStefan Oprea
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSSMario Hernandez
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applicationsVittorio Vittori
 
Best Practices for Building Sites in dotCMS
Best Practices for Building Sites in dotCMSBest Practices for Building Sites in dotCMS
Best Practices for Building Sites in dotCMSMichael Fienen
 
SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...
SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...
SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...Anindita Bhattacharya
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Customizing ERModernLook Applications
Customizing ERModernLook ApplicationsCustomizing ERModernLook Applications
Customizing ERModernLook ApplicationsWO Community
 
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
 
Wordpress workflow for an agency world
Wordpress workflow for an agency worldWordpress workflow for an agency world
Wordpress workflow for an agency worldChris Lowe
 

Ähnlich wie BEM it! (20)

BEM methodology overview
BEM methodology overviewBEM methodology overview
BEM methodology overview
 
BEM for Javascript at CampJS III
BEM for Javascript at CampJS IIIBEM for Javascript at CampJS III
BEM for Javascript at CampJS III
 
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
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
 
Web technologies-course 02.pptx
Web technologies-course 02.pptxWeb technologies-course 02.pptx
Web technologies-course 02.pptx
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
Best Practices for Building Sites in dotCMS
Best Practices for Building Sites in dotCMSBest Practices for Building Sites in dotCMS
Best Practices for Building Sites in dotCMS
 
DHTML
DHTMLDHTML
DHTML
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 
SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...
SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...
SUG Bangalore - Overview of Sitecore Experience Accelerator with Pratik Satik...
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
dmBridge & dmMonocle
dmBridge & dmMonocledmBridge & dmMonocle
dmBridge & dmMonocle
 
Customizing ERModernLook Applications
Customizing ERModernLook ApplicationsCustomizing ERModernLook Applications
Customizing ERModernLook Applications
 
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
 
Wordpress workflow for an agency world
Wordpress workflow for an agency worldWordpress workflow for an agency world
Wordpress workflow for an agency world
 
SXA in action
SXA in actionSXA in action
SXA in action
 
BEM
BEMBEM
BEM
 

Kürzlich hochgeladen

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Kürzlich hochgeladen (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

BEM it!

  • 1. by Max Shirshin Frontend Team Lead, Deltamethod Consultant, Yandex BEM it! BEM Methodology for small companies with high expectations
  • 3. Web development needs: ● Methodologies, not frameworks ● Same entities across different technologies ● Scalability
  • 4. BEM to the rescue
  • 5. What is BEM? “BEM claims that three basic entities (Blocks, Elements, and Modifiers) are 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.”
  • 6. What is BEM? ● A methodology “Theoretical underpinning” for methods and best practices
  • 7. What is BEM? ● A methodology “Theoretical underpinning” for methods and best practices ● Originally introduced by Yandex — www.yandex.ru (English: www.yandex.com) — 200+ Yandex services using full BEM stack (methodology + tools) — 19 million users daily audience
  • 8. What is BEM? ● A methodology “Theoretical underpinning” for methods and best practices ● Originally introduced by Yandex — www.yandex.ru (English: www.yandex.com) — 200+ Yandex services using full BEM stack (methodology + tools) — 19 million users daily audience ● Used by external projects — other services — tools / libraries
  • 10. What is BEM? BLOCK – Standalone part of an interface: ● button ● text field ● flyout ● heading ● menu
  • 11. What is BEM? BLOCK – Standalone part of an interface: ● button ● text field ● flyout ● heading ● menu – Re-usable in different contexts – Self-sufficient
  • 12. What is BEM? ELEMENT – An integral part of a block: ● button ● text field ● flyout ● heading ● menu
  • 13. What is BEM? ELEMENT – An integral part of a block: ● button icon ● text field label ● flyout title ● heading logo ● menu item
  • 14. What is BEM? ELEMENT – An integral part of a block: ● button icon ● text field label ● flyout title ● heading logo ● menu item – No standalone meaning outside of a block – Some blocks have no elements
  • 15. What is BEM? MODIFIER – Defines property or state on a block or element: ● button ● text field ● flyout ● heading ● menu item
  • 16. What is BEM? MODIFIER – Defines property or state on a block or element: ● button color ● text field disabled state ● flyout alignment ● heading level ● menu item bullet type
  • 17. What is BEM? MODIFIER – Defines property or state on a block or element: ● button color ● text field disabled state ● flyout alignment ● heading level ● menu item bullet type – Multiple modifiers may co-exist on a single block/element
  • 18. BEM + DOM ● Blocks are mapped to DOM
  • 19. BEM + DOM ● Blocks are mapped to DOM ● Blocks/elems/mods are denoted with CSS classes
  • 20. BEM + DOM ● Blocks are mapped to DOM ● Blocks/elems/mods are denoted with CSS classes ● DOM nodes can be “shared”: you can mix (block1 + block2) or (element1 + block2) on a same node
  • 21. BEM markup forms a semantic overlay over the existing DOM structure. This overlay is called a BEM tree.
  • 22. BEM HOWTO for your beloved project with benefits explained
  • 24. CSS naming conventions “BEM uses CSS class names to denote blocks, elements and modifiers.”
  • 26. 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>
  • 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>
  • 30. CSS naming conventions <ul class=”b-menu b-menu_horizontal”> <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>
  • 31. CSS naming conventions <ul class=”b-menu b-menu_horizontal”> <li class=”b-menu__item b-menu__item_pos_first”> <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>
  • 32. Additional notes on CSS ● Page (Document) is also a block
  • 33. Additional notes on CSS ● Page (Document) is also a block ● Layouts are blocks (same rules apply)
  • 34. Additional notes on CSS ● Page (Document) is also a block ● Layouts are blocks (same rules apply) ● No CSS outside of blocks
  • 35. Additional notes on CSS ● Page (Document) is also a block ● Layouts are blocks (same rules apply) ● No CSS outside of blocks ● No common CSS resets (block independency!)
  • 36. Additional notes on CSS ● Page (Document) is also a block ● Layouts are blocks (same rules apply) ● No CSS outside of blocks ● No common CSS resets (block independency!) ● No “shared” styles (no need)
  • 37. Additional notes on CSS ● Page (Document) is also a block ● Layouts are blocks (same rules apply) ● No CSS outside of blocks ● No common CSS resets (block independency!) ● No “shared” styles (no need) ● DOM tree → BEM tree
  • 39. Benefits! Drop tag names and IDs ● Faster selectors ● Re-use same semantic block on: — <DIV class=”b-block”> — <SPAN class=”b-block”> — <TABLE class=”b-block”>
  • 41. Benefits! CSS specificity magic solved Priority of CSS rules: by specificity first, then by rule order
  • 42. Benefits! CSS specificity magic solved Priority of CSS rules: by specificity first, then by rule order td.odd { background-color: gray } td.even { background-color: white } .highlighted { background-color: yellow } <TD class="odd highlighted"> <!-- Still gray, baby :-( --> </TD>
  • 43. Benefits! CSS specificity magic solved Priority of CSS rules: by specificity first, then by rule order td.odd { background-color: gray } td.even { background-color: white } td.highlighted { background-color: yellow } <TD class="odd highlighted"> <!-- This works, I'm yellow now --> </TD>
  • 45. 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?
  • 46. Benefits! Bye-bye CSS cascade?! ...well, not exactly. Example of an element affected by a block modifier: /* hide labels for disabled text fields */ .b-text-input_disabled .b-text-input__label { display: none; }
  • 48. JavaScript Components → Blocks Work with BEM tree, not DOM tree
  • 49. 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
  • 50. 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
  • 51. JavaScript Twitter Flight (used by Deltamethod) http://flightjs.github.io ● Self-contained components, 100% event-driven ● Based on jQuery; AMD-friendly; BEM-friendly ● Built-in syntax sugar for predefined selectors (good for BEM tree) ● [Shameless self-promo] Try Flight with Reggirt: http://github.com/ingdir/reggirt jQuery plugin that emulates event capturing (opposite of event bubbling)
  • 52. JavaScript Twitter Flight (used by Deltamethod) http://flightjs.github.io ● Self-contained components, 100% event-driven ● Based on jQuery; AMD-friendly; BEM-friendly ● Built-in syntax sugar for predefined selectors (good for BEM tree) ● [Shameless self-promo] Try Flight with Reggirt: http://github.com/ingdir/reggirt jQuery plugin that emulates event capturing (opposite of event bubbling)
  • 53. Benefits! HTML is no longer semantic. JavaScript is.
  • 55. BEM is the universal language for developers and designers, the bridge across technology gaps.
  • 56. UX + Frontend ● Design a style guide
  • 57. UX + Frontend ● Design a style guide ● Keep it up-to-date
  • 58. UX + Frontend ● Design a style guide ● Keep it up-to-date, always!
  • 59. UX + Frontend ● Design a style guide ● Keep it up-to-date, always! ● Build new screens quickly
  • 60. UX + Frontend Build your block library. The code itself is the styleguide.
  • 61. Benefits! ● Prototyping mapped to code from day 1
  • 62. Benefits! ● Prototyping mapped to code from day 1 ● Code mapped to prototypes from day 1
  • 64. 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
  • 65. File and folder structure Advanced structure to expose semantics /block /css block.css block__elem1.css block__elem2.css block_mod.css /js block.js /template block.tpl block__elem1.tpl block__elem2.tpl
  • 66. File and folder structure Advanced structure to expose semantics /block /css block.css block__elem1.css block__elem2.css block_mod.css /js block.js /template block.tpl block__elem1.tpl block__elem2.tpl
  • 67. Benefits! ● Unified structure for automation ● Redefinition levels: different libraries, same structure /common /b-block /css block.css /template block.tpl /app1 /b-block /css block__elem1.css /js block.js /template block__elem1.tpl +
  • 68. 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