SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
Scalable CSS
Architecture
Artur Kot & Michał Pierzchała
Does it even exist?
Scalable CSS?
Maintainable CSS?
What we need
Modularity
Encapsulation
Predictability
What we have
What we really have
Cascade
Global namespace
Selectors specificity
Solution?
–David Heinemeier Hansson
“Convention over configuration”
Like in JavaScript
Embrace the good parts
Throw away the bad parts
Introducing
ITCSS
Inverted
Triangle
CSS
// main.scss
@import 'settings/*';
@import 'tools/*';
@import 'generic/*';
@import 'elements/*';
@import 'objects/*';
@import 'components/*';
@import 'trumps/*';
used with preprocessors
font definitions, colours, variables, etc.
1. Settings
2. Tools
globally used mixins and functions
normalising styles
box-sizing
3. Generic
4. Elements
bare HTML elements
reset lists, anchors, etc
simple & reusable
containers, grids, global animations, etc
5. Objects
6. Components
actual UI
CSS ❤ components
utilities and helper classes
visibility, alternative colours
override anything
7. Trumps
Some constraints
and recommendations
Groups order is crucial
(Inner order doesn’t matter)
Avoid “!important”
Use BEM
(Block Element Modifier)
<section class="c-component c-component--small">
<div class="c-component__bg"></div>
<h2 class="c-component__heading">A component!</h2>
<div class="c-component__child">
Lorem ipsum dolor sit amet, consectetur adipisicing elit
<button class="c-component__grandchild">inside</button>
</div>
</section>
• .[component-name]__[child]—[modifier]
• Remember that it’s on only a convention!
• Use 🍌 instead of __ or 🍓instead —

if you like
• Important: separation of the parent
element and its children.
• Be consistent.
JS hooks
• .js-[name]
• readonly to identify DOM elements for JS
• can’t be styled!
State classes
• .is-[name]
• .has-[name]
• should be used in favour of —modifiers
in case a component changes its state
after the page is loaded
• handy to use with JS
Resist from nesting
Temptation to target tags
.c-my-list li {
[item styles]
}
<ul>
<li>
<div class=”c-some-component-with-a-list”>
<ul>
<li>another list!</li>
<li>
and now you need to override
.c-my-list li with stronger selector...</li>
</ul>
</div>
</li>
</ul>
• You can’t predict the future. It’s possible that a
sneaky designer could design a nested list inside
your element. What to do then? More nesting. :)
• It, obviously, works but what if you’ve got identical
list but with divs instead of lis?
• Usually, nesting is like a domino effect: one
innocent nested selector results in dozen deeper
nested selectors. Avoid when possible.
You can’t entirely avoid
nesting. It’s impossible.
The goal is to minimise it and its side effects.
.c-component {
/* third-party code */
.super-slick-slider {
float: left !important;
}
/* state affects children */
&.is-open {
.c-component__grandchild {
display: block;
}
.c-component__inner {
display: flex;
}
.c-component__inner-most {
color: red;
}
}
}
.c-component {
/* state classes */
&.is-open,
&.has-popup {
display: block;
}
/* state pseudo-selectors */
&:hover,
&:focus,
&:nth-child(2n) {
border-bottom: 1px solid;
}
/* relationships */
+ &, ~ &, > &, * {
display: none;
}
}
Do Repeat Yourself
If it makes your life easier (usually does)
extra bytes will be squashed by gzip anyway…
Tricky MQ nesting
.c-component {
@media {
&.is-cos {
@media {
color: red;
}
}
}
}
.c-component {
color: blue;
@media {
color: red;
}
&.is-cos {
@media {
color: yellow;
}
}
}
BAD GOOD
Keep it tidy
Sync filenames with naming
/* _my-pretty-component.scss: */
.c-my-pretty-cmp {
color: brown;
}
/* _my-pretty-component.scss: */
.c-my-pretty-component {
color: blue;
}
BAD GOOD
Do not mix components with
each other
Not in stylesheets
/* Some time before */
.c-my-box {
width: 320px;
}
.c-my-box__inner {
padding: 20px;
background: blue;
.c-my-other-box {
color: white;
}
}
/* Few weeks later… */
.c-my-other-box {
color: white;
/* Doesn’t work :( */
&--pink {
color: pink;
}
}
Nor in the markup
<div class=”c-boxie c-footer”></div>
.c-boxie {
display: block;
}
.c-footer {
display: flex;
}
What display will it get?
Objects for reusability
Components for explicitness
Use objects for mixing with component!
<div class=”o-boxie c-footer”></div>
.o-boxie {
display: block;
}
Trumps are the new
“!important”
<h3 class=”o-title t-color-blue”>Heading</h3>
.o-title {
font-size: 12px;
color: red;
}
/* trumps/utilities.scss */
.t-color-blue {
color: blue;
}
It’s easier to maintain separated UI components
than ones mixed in HTML markup
Take it serious
It Just Works™
for CSS, SCSS, LESS
Piece of cake
Critical CSS or PRPL?
/* critical.index.scss */
@import 'settings/*';
@import ‘tools/*';
@import 'generic/*';
@import 'elements/*';
@import 'components/colorbar';
@import 'components/header';
@import 'components/hero';
Kinda
Use in existing
messy codebase?
Gradual adoption
Needs pre-/post-processor (sorry CSS 😞)
#create #strongest #selector {
@import 'settings/*';
@import 'tools/*';
@import 'generic/*';
@import 'elements/*';
@import 'objects/*';
@import 'components/*';
@import 'trumps/*';
}
With predefined and ready to use (or remove) components
Featured in Chisel,
our new project generator
ITCSS
IS
AWESOMER
Cool JS-based alternatives
CSS Modules
CSS in JS
Available with
Webpack & Browserify
Thank you.
Artur Kot & Michał Pierzchała

Contenu connexe

En vedette

Ad server cassandra
Ad server cassandraAd server cassandra
Ad server cassandra
dist_bp
 
Atividade3FernandoLucioSoaresRamos
Atividade3FernandoLucioSoaresRamosAtividade3FernandoLucioSoaresRamos
Atividade3FernandoLucioSoaresRamos
FLSR1
 

En vedette (18)

Put A Map On It! Enhanced geolocation in WordPress with Geo Mashup
Put A Map On It! Enhanced geolocation in WordPress with Geo MashupPut A Map On It! Enhanced geolocation in WordPress with Geo Mashup
Put A Map On It! Enhanced geolocation in WordPress with Geo Mashup
 
Teste unitário
Teste unitárioTeste unitário
Teste unitário
 
Ad server cassandra
Ad server cassandraAd server cassandra
Ad server cassandra
 
Cassandra cql
Cassandra cqlCassandra cql
Cassandra cql
 
Apache camel
Apache camelApache camel
Apache camel
 
Aparato excretor y circulatorio.
Aparato excretor y circulatorio.Aparato excretor y circulatorio.
Aparato excretor y circulatorio.
 
No pain, no gain. CSS Code Reviews FTW.
No pain, no gain. CSS Code Reviews FTW.No pain, no gain. CSS Code Reviews FTW.
No pain, no gain. CSS Code Reviews FTW.
 
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...
 
Tech Talk Buscapé - Redis
Tech Talk Buscapé - RedisTech Talk Buscapé - Redis
Tech Talk Buscapé - Redis
 
Значення сайту навчального закладу в створенні єдиного інформаційного простору
Значення сайту навчального закладу в створенні єдиного інформаційного просторуЗначення сайту навчального закладу в створенні єдиного інформаційного простору
Значення сайту навчального закладу в створенні єдиного інформаційного простору
 
Properties of titanium and titanium alloys
Properties of titanium and titanium alloysProperties of titanium and titanium alloys
Properties of titanium and titanium alloys
 
Atividade3FernandoLucioSoaresRamos
Atividade3FernandoLucioSoaresRamosAtividade3FernandoLucioSoaresRamos
Atividade3FernandoLucioSoaresRamos
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
 
CSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NECSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NE
 
Tech Talk Buscapé - Clean Code
Tech Talk Buscapé - Clean CodeTech Talk Buscapé - Clean Code
Tech Talk Buscapé - Clean Code
 
отчет о проведении мероприятий
отчет о проведении мероприятий отчет о проведении мероприятий
отчет о проведении мероприятий
 
Carnaval
CarnavalCarnaval
Carnaval
 
OOCSS and SMACSS Case Study
OOCSS and SMACSS Case StudyOOCSS and SMACSS Case Study
OOCSS and SMACSS Case Study
 

Similaire à Scalable CSS Architecture

CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
Mats Bryntse
 

Similaire à Scalable CSS Architecture (20)

Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule
 
CSS Architecture: Writing Maintainable CSS
CSS Architecture: Writing Maintainable CSSCSS Architecture: Writing Maintainable CSS
CSS Architecture: Writing Maintainable CSS
 
Introduction to HTML-CSS-Javascript.pdf
Introduction to HTML-CSS-Javascript.pdfIntroduction to HTML-CSS-Javascript.pdf
Introduction to HTML-CSS-Javascript.pdf
 
INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
 
Webdev bootcamp
Webdev bootcampWebdev bootcamp
Webdev bootcamp
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
CSS 101
CSS 101CSS 101
CSS 101
 
Rendering The Fat
Rendering The FatRendering The Fat
Rendering The Fat
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
 
Advance Css
Advance CssAdvance Css
Advance Css
 
Advance Css 1194323118268797 5
Advance Css 1194323118268797 5Advance Css 1194323118268797 5
Advance Css 1194323118268797 5
 

Dernier

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Scalable CSS Architecture