Movatterモバイル変換


[0]ホーム

URL:


PPTX, PDF1,764 views

CSS Architecture: Writing Maintainable CSS

The document discusses the challenges of maintaining scalable and organized CSS architecture, emphasizing the need for a structured approach to handle growing complexity and technical difficulties. It outlines key principles for writing maintainable CSS, focusing on component independence, clear naming conventions, and avoiding excessive specificity. Additionally, it highlights the importance of collaboration between designers and front-end engineers to ensure that CSS effectively supports component-based design systems.

Related topics:

Embed presentation

Downloaded 21 times
CSS ArchitectureWriting maintainable CSSAlexei Skachykhin – Software EngineeriTechArt, 2015
“Writing CSS is easy. Scaling CSSand keeping it maintainable is not.”Ben Frain
Guess what makesit hard to maintain
“I don’t understand the cultural fascination withfailure being the source of great lessons to belearned. You might know what won’t work, but youstill don’t know what will work.”BasecampExcerpt from “Rework”
What’s missing?CSS that works to spec isn’t enough, itshould be considered as a baseline
We need a plan to keep CSS styles organized.We call such plan an architecture
Evolving Design
Growing Complexity7,046Rules10KSelectors16,8KDeclarations90Unique Colors
Growing Complexity3,938Rules5,164Selectors9,826Declarations46Unique Colors
Repetitive Design
Repetitive Design“We’re not designing pages,we’re designing systems of components.”Stephen Hay
Technical Difficulties Source order affects application order Specificity is hard to deal with CSS operate in global scope Permissive by its nature
1. Evolving Design2. Growing Complexity3. Repetitive Design4. Technical Difficulties
It is time to follow architectureand cleanup our CSS
Building BlocksUI consists of components, wherecomponent is any distinguishable elementof the design
Building BlocksWriting CSS is not about making HTMLelements look like provided PSD, buttranslating system of components into Webcompatible format
.contact-item {float: left;font-size: 28px;.contact-item .contact-item__info {margin-top: 4px;margin-left: 20px;padding-left: 31px;}.contact-item .contact-item__title {margin: 0;font-family: 'Lato', sans-serif;font-size: 16px;font-weight: bold;}.contact-item .contact-item__text {margin: 1px 0 14px;font-size: 14px;}}.subscribe {.clearfix();.field-group {.clearfix();}.sign-up-button {.secondary-button;.variant-action;display: block;border: none;}ul {margin: 5px;li {display: inline-block;}}}COMPONENT STYLED HTML
Design and markup are inseparable.Designers and Front-End Engineers must speakubiquitous language to succeed.
CSS ArchitectureComponents &Other StylesDependencyManagementPhysical Structure &Deployment
No constraints?
Goals of ArchitecturePredictable ReusableMaintainable Scalable
Goals of ArchitecturePredictable ReusableMaintainable ScalableMinimalComplexity
“Everyone else in the W3C CSS Working Group, thegroup which defines the future of CSS, fits the profileof a developer much more than that of a designer.”Lea Verou
Who’s in camp?
Existing Solutions BEM OOCSS SMACSS Atomic CSS MCSS ITCSS
Components
#1 DOM IndependencyCSS component styles must not rely onparticular DOM structure
HERE
Examplediv.social-links {> div a {color: blue;}} Visual styles are tightly coupled withmarkup which makes them hard toevolve Reusability of component is limited Ambiguity that leads to growth ofspecificity
RuleAvoid any signs of DOM elements in CSScode including references to HTML tags, ID(#) and (>) child selectors
RuleCSS selectors must convey semantics of thecomponent and it’s integral parts. Classselector conveys a lot, element selectoralmost none
Example.social-links {.social-links__item {color: blue;}}
#2 Location IndependencyCSS component styles must not rely oncomponent’s location on a page
HEREHERE
Example.button {color: white;}.sidebar {.button {color: orange;}} Component is no longer self containedentity and its visual appearance is notpredictable at dev time Leads to growth of specificity
RuleComponent styles must not be written inreliance on their location on a page, insteadprovide location independent variations thatcan be used anywhere
“Instead of saying - The buttons need to be smallerwhen they’re in the header, we need to be saying - Wehave a smaller variant of our buttons, and it’s these thatwe use in the header.”Harry Roberts
.button {color: white;/* Other declarations */&.button--variant-action {color: orange;}}Example
#3 Limited ComplexityCSS components can be complex and haveintegral parts, but no more than having 1 (2)layers of descendant styles
HERE
Example.filter {.filter__header {.filter__header__icon {/* Declarations */}}.filter__list {.filter__list__link {/* Declarations */}}} Component is too complex whichmakes it hard to maintain Following that style may lead tounnecessary dependencies betweenintegral parts
RuleIf CSS styles have no dependency they mustnot form parent-child relationship
RuleComplex components must be split intosimpler components
.filter {.filter__header {}.filter__icon {/* Declarations */}.filter__list {}.filter__link {/* Declarations */}}Example
#4 Enforced NamingAll aspects of component definition must be named in away to communicate their relationship clearly andprotect from incorrect use
.infobox /* Block */ {.infobox__body /* Element */ {}.infobox__footer {}.infobox__title {}&.infobox--size-full /* Modifier */ {}}Example
#5 Explicit StatesDynamic behavior must be implemented with stateclasses that JavaScript toggles. No direct stylemanipulation is allowed with JavaScript.
HERE
open: function () {elements.root.show();elements.trigger.css('color', 'blue');},close: function () {elements.root.hide();elements.trigger.css('color', 'white');}Example Visual appearance of component isnow split across JavaScript and CSSwhich makes is hard to maintain There is no simple undo operationfor setting style properties inJavaScript so previous state has tobe maintained somewhere or inlinestyles manipulated directly
open: function () {elements.root.addClass('state-open');elements.trigger.addClass('state-active');},close: function () {elements.root.removeClass('state-open');elements.trigger.removeClass('state-active');}Example
RuleGlobal states must not collide with localstates to avoid overrides in CSS
.state-hidden {display: none;}.infobox {display: inline-block;&.state-hidden {display: inline-block;visibility: hidden;}}Example Component is no longer self containedwhich causes inclusion of overridedeclarations In some cases may lead to a need tohave !importants
.global-state-hidden {display: none;}.infobox {display: inline-block;&.state-hidden {visibility: hidden;}}Example
#6 JavaScript HooksNever use component classes to select elements withJavaScript. Introduce specialized classes just for thesake of selecting elements.
HERE
Examplevar elements = {mailing_list: internal.$e,form: internal.$e.find('.social-widget__query'),submit_button: internal.$e.find('.button'),submit_button_text: internal.$e.find('span'),validation_message: internal.$e.find('.social-widget__validation-message')}; Hard to modify component styles due to dependencies inJavaScript. Makes whole component fragile
Example<div class="social-widget social-widget--inversed js-mailing-list"><div class="social-widget__title">Stay in the loop</div><form class="social-widget__query js-mailing-list-form"><input class="js-mailing-list-email" type="text" name="email" placeholder="Email address"><label class="button"><span class="js-mailing-list-submit-button-text">Submit</span><input class="js-mailing-list-submit-button" type="submit"></label></form><div class="js-mailing-list-validation-message social-widget__validation-message state-hidden">Email is not in correct format!</div></div>
#7 Local Media QueriesResponsiveness of a page must be based onresponsiveness of each component thus Media Querymust be local to a component
.blog-entry {.blog-entry-body {/* Declarations */}}.infobox {}@media @phone {.blog-entry {.blog-entry-body {/* Declarations */}}.infobox {}}Example Code duplication makes componentshard to maintain Components are not self-containedwhich makes the outcome lesspredictable at dev time
.blog-entry {.blog-entry-body {margin-right: @gutter / 2;margin-bottom: @gutter / 2;margin-left: @gutter / 2;@media @phone {margin-left: @gutter_phone / 2;margin-right: @gutter_phone / 2;}}}Example
.infobox /* Component */ {.infobox__body /* Integral Part */ {}&.infobox--size-full /* Variant */ {}&.state-active /* State */ {}@media @phone /* Responsive */ {}}.js-infobox /* JavaScript Hook */Anatomy of Component
#8 Layout vs VisualLayout aspects should be moved to dedicatedcomponents or integral parts
HERE
.infobox {/* Layout */float: left;padding-left: @half-col-gutter;padding-right: @half-col-gutter;width: 33.33%;/* Visual */background-color: green;padding: 10px; /* Collision */}Example Limits reusability Usually require additional htmlelements just as styling hooks
Grid based layout is an emerging trend in Web andGraphics design
.grid-row {.clearfix();.grid-row__column {float: left;padding-left: @half-col-gutter;padding-right: @half-col-gutter;width: 33.33%;}}.infobox {background-color: green;padding: 10px;}Example
#9 Container vs ContentContainer components must define layout and sizeconstraints, content components – visual look(occasionally size constraints too)
RuleDon’t make any assumptions about contenton container level
RuleDevelop CSS components to be containeragnostic
Other Styles
Types of StylesBase(Normalize, Reset)Utilities(clearfix, valign)Typography(Fonts, Headings, …)Constants(Colors, Sizes, …)
Physical Structure &Deployment
Physical StructureSingle file forall of the stylesSingle file withcommentsOne file pertype of stylesOne file percomponent
Fallacies Use id selectors for performance reasons Too many classes is a bad thing, style based on tags Nest CSS selectors to follow DOM hierarchy Put all styles into single file all the time because it iseasier to maintain Introduce lots of utility classes to have greater flexibilitywhen styling things
Thank you!Forward your questions toalexei.skachykhin@live.com

Recommended

PPTX
HTML, CSS and Java Scripts Basics
PDF
JavaScript Fetch API
PPT
Cascading Style Sheets (CSS) help
PDF
Introduction to HTML and CSS
PPTX
HTML/HTML5
PDF
JavaScript guide 2020 Learn JavaScript
PDF
JavaScript - Chapter 10 - Strings and Arrays
PPTX
Java script errors &amp; exceptions handling
PPTX
1 03 - CSS Introduction
PDF
CSS notes
PPT
Introduction to BOOTSTRAP
PDF
Intro to HTML and CSS basics
PDF
CSS Day: CSS Grid Layout
PPTX
Lab #2: Introduction to Javascript
PPTX
Introduction to Javascript
PPTX
Html, CSS & Web Designing
PPT
Introduction to PHP
PDF
CSS Best practice
PPT
Asp.net
PPTX
Flexbox
PPTX
Html forms
PPTX
Introducing CSS Grid
PDF
CSS Grid
PDF
Regular expression in javascript
PDF
Html / CSS Presentation
PDF
World of CSS Grid
PPT
JavaScript - Part-1
PPT
Java Script ppt
PDF
Atomic design
PDF
Maintainable CSS

More Related Content

PPTX
HTML, CSS and Java Scripts Basics
PDF
JavaScript Fetch API
PPT
Cascading Style Sheets (CSS) help
PDF
Introduction to HTML and CSS
PPTX
HTML/HTML5
PDF
JavaScript guide 2020 Learn JavaScript
PDF
JavaScript - Chapter 10 - Strings and Arrays
PPTX
Java script errors &amp; exceptions handling
HTML, CSS and Java Scripts Basics
JavaScript Fetch API
Cascading Style Sheets (CSS) help
Introduction to HTML and CSS
HTML/HTML5
JavaScript guide 2020 Learn JavaScript
JavaScript - Chapter 10 - Strings and Arrays
Java script errors &amp; exceptions handling

What's hot

PPTX
1 03 - CSS Introduction
PDF
CSS notes
PPT
Introduction to BOOTSTRAP
PDF
Intro to HTML and CSS basics
PDF
CSS Day: CSS Grid Layout
PPTX
Lab #2: Introduction to Javascript
PPTX
Introduction to Javascript
PPTX
Html, CSS & Web Designing
PPT
Introduction to PHP
PDF
CSS Best practice
PPT
Asp.net
PPTX
Flexbox
PPTX
Html forms
PPTX
Introducing CSS Grid
PDF
CSS Grid
PDF
Regular expression in javascript
PDF
Html / CSS Presentation
PDF
World of CSS Grid
PPT
JavaScript - Part-1
PPT
Java Script ppt
1 03 - CSS Introduction
CSS notes
Introduction to BOOTSTRAP
Intro to HTML and CSS basics
CSS Day: CSS Grid Layout
Lab #2: Introduction to Javascript
Introduction to Javascript
Html, CSS & Web Designing
Introduction to PHP
CSS Best practice
Asp.net
Flexbox
Html forms
Introducing CSS Grid
CSS Grid
Regular expression in javascript
Html / CSS Presentation
World of CSS Grid
JavaScript - Part-1
Java Script ppt

Viewers also liked

PDF
Atomic design
PDF
Maintainable CSS
PPTX
Java bmi
PPT
Ucsf 2 3
PPTX
The Duty to Report Up the Chain
PDF
Building Programming Abstractions for Wireless Sensor Networks Using Watershe...
byM H
 
DOCX
Focus group summary of finished product
PPT
Urrunaga
PPT
Generacion de las computadoras
PPTX
Ucsf 3 3 ppt
PPTX
5M Seth Civilization
 
PPTX
Course 2 week 6 lesson 10
PDF
Corporate Gift Watches
PPT
дорогой дружбы и добра
PPTX
Leroy Almon Sr. Bird
PPTX
Survey
 
PDF
Eliv 2015 bosch-hammel-presentation_v3.4
PDF
Explore europewww.Tripmart.com
PPT
Elosu
PPSX
Chronology of computing
Atomic design
Maintainable CSS
Java bmi
Ucsf 2 3
The Duty to Report Up the Chain
Building Programming Abstractions for Wireless Sensor Networks Using Watershe...
byM H
 
Focus group summary of finished product
Urrunaga
Generacion de las computadoras
Ucsf 3 3 ppt
5M Seth Civilization
 
Course 2 week 6 lesson 10
Corporate Gift Watches
дорогой дружбы и добра
Leroy Almon Sr. Bird
Survey
 
Eliv 2015 bosch-hammel-presentation_v3.4
Explore europewww.Tripmart.com
Elosu
Chronology of computing

Similar to CSS Architecture: Writing Maintainable CSS

PDF
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
PPTX
Writing Scalable and Maintainable CSS
PPTX
Css methods architecture
PPTX
Rock Solid CSS Architecture
PDF
Modular HTML & CSS Workshop
PDF
Modular HTML & CSS Turbo Workshop
PDF
Css Systems
KEY
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
PDF
Teams, styles and scalable applications
PDF
What is Modular CSS?
PDF
React Storybook, Atomic Design, and ITCSS
PPTX
CSS Walktrough Internship Course
PDF
Jonathan Snook - Falling to pieces: the componentization of the web
PDF
Scalable CSS Architecture
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
PPT
Css best practices style guide and tips
PDF
CSS- Smacss Design Rule
PPT
Web design-workflow
PDF
Styleguide-Driven Development: The New Web Development
PDF
CSS: a rapidly changing world
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Writing Scalable and Maintainable CSS
Css methods architecture
Rock Solid CSS Architecture
Modular HTML & CSS Workshop
Modular HTML & CSS Turbo Workshop
Css Systems
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
Teams, styles and scalable applications
What is Modular CSS?
React Storybook, Atomic Design, and ITCSS
CSS Walktrough Internship Course
Jonathan Snook - Falling to pieces: the componentization of the web
Scalable CSS Architecture
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Css best practices style guide and tips
CSS- Smacss Design Rule
Web design-workflow
Styleguide-Driven Development: The New Web Development
CSS: a rapidly changing world

More from Alexei Skachykhin

PPTX
Representational State Transfer
PPTX
Web Real-time Communications
PPTX
Code Contracts
PPTX
JavaScript as Development Platform
PDF
HTML5 Comprehensive Guide
PPTX
Windows 8
Representational State Transfer
Web Real-time Communications
Code Contracts
JavaScript as Development Platform
HTML5 Comprehensive Guide
Windows 8

Recently uploaded

PDF
Constraints First - Why Our On-Prem Ticketing System Starts With Limits, Not ...
PDF
Red Hat Summit 2025 - Triton GPU Kernel programming.pdf
PDF
KoderXpert – Odoo, Web & AI Solutions for Growing Businesses
PDF
INTRODUCTION TO DATABASES, MYSQL, MS ACCESS, PHARMACY DRUG DATABASE.pdf
DOCX
How to Change Classic SharePoint to Modern SharePoint (An Updated Guide)
PDF
Virtual Study Circles Innovative Ways to Collaborate Online.pdf
PPTX
Application Security – Static Application Security Testing (SAST)
PDF
What Is A Woman (WIAW) Token – Smart Contract Security Audit Report by EtherA...
PDF
nsfconvertersoftwaretoconvertNSFtoPST.pdf
PPTX
Managed Splunk Partner vs In-House: Cost, Risk & Value Comparison
PDF
Here’s the case study that shows how companies lose ₹2–6 Cr annually due to m...
PDF
Cybersecurity Alert- What Organisations Must Watch Out For This Christmas Fes...
PDF
Imed Eddine Bouchoucha | computer engineer | software Architect
PDF
Database Management Systems(DBMS):UNIT-II Relational Data Model BCA SEP SEM ...
PDF
Data structure using C :UNIT-I Introduction to Data structures and Stacks BCA...
PPTX
Reimagining Service with AI Voice Agents | Webinar
PPTX
AI Clinic Management Software for Pulmonology Clinics Bringing Clarity, Contr...
PDF
Advanced Prompt Engineering: The Art and Science
PDF
IT Estate Modernization: Transform Your Infrastructure for the Future .pdf
PDF
Database Management Systems(DBMS):UNIT-I Introduction to Database(DBMS) BCA S...
Constraints First - Why Our On-Prem Ticketing System Starts With Limits, Not ...
Red Hat Summit 2025 - Triton GPU Kernel programming.pdf
KoderXpert – Odoo, Web & AI Solutions for Growing Businesses
INTRODUCTION TO DATABASES, MYSQL, MS ACCESS, PHARMACY DRUG DATABASE.pdf
How to Change Classic SharePoint to Modern SharePoint (An Updated Guide)
Virtual Study Circles Innovative Ways to Collaborate Online.pdf
Application Security – Static Application Security Testing (SAST)
What Is A Woman (WIAW) Token – Smart Contract Security Audit Report by EtherA...
nsfconvertersoftwaretoconvertNSFtoPST.pdf
Managed Splunk Partner vs In-House: Cost, Risk & Value Comparison
Here’s the case study that shows how companies lose ₹2–6 Cr annually due to m...
Cybersecurity Alert- What Organisations Must Watch Out For This Christmas Fes...
Imed Eddine Bouchoucha | computer engineer | software Architect
Database Management Systems(DBMS):UNIT-II Relational Data Model BCA SEP SEM ...
Data structure using C :UNIT-I Introduction to Data structures and Stacks BCA...
Reimagining Service with AI Voice Agents | Webinar
AI Clinic Management Software for Pulmonology Clinics Bringing Clarity, Contr...
Advanced Prompt Engineering: The Art and Science
IT Estate Modernization: Transform Your Infrastructure for the Future .pdf
Database Management Systems(DBMS):UNIT-I Introduction to Database(DBMS) BCA S...

CSS Architecture: Writing Maintainable CSS

  • 1.
    CSS ArchitectureWriting maintainableCSSAlexei Skachykhin – Software EngineeriTechArt, 2015
  • 2.
    “Writing CSS iseasy. Scaling CSSand keeping it maintainable is not.”Ben Frain
  • 4.
    Guess what makesithard to maintain
  • 8.
    “I don’t understandthe cultural fascination withfailure being the source of great lessons to belearned. You might know what won’t work, but youstill don’t know what will work.”BasecampExcerpt from “Rework”
  • 9.
    What’s missing?CSS thatworks to spec isn’t enough, itshould be considered as a baseline
  • 10.
    We need aplan to keep CSS styles organized.We call such plan an architecture
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    Repetitive Design“We’re notdesigning pages,we’re designing systems of components.”Stephen Hay
  • 16.
    Technical Difficulties Sourceorder affects application order Specificity is hard to deal with CSS operate in global scope Permissive by its nature
  • 17.
    1. Evolving Design2.Growing Complexity3. Repetitive Design4. Technical Difficulties
  • 18.
    It is timeto follow architectureand cleanup our CSS
  • 19.
    Building BlocksUI consistsof components, wherecomponent is any distinguishable elementof the design
  • 21.
    Building BlocksWriting CSSis not about making HTMLelements look like provided PSD, buttranslating system of components into Webcompatible format
  • 22.
    .contact-item {float: left;font-size:28px;.contact-item .contact-item__info {margin-top: 4px;margin-left: 20px;padding-left: 31px;}.contact-item .contact-item__title {margin: 0;font-family: 'Lato', sans-serif;font-size: 16px;font-weight: bold;}.contact-item .contact-item__text {margin: 1px 0 14px;font-size: 14px;}}.subscribe {.clearfix();.field-group {.clearfix();}.sign-up-button {.secondary-button;.variant-action;display: block;border: none;}ul {margin: 5px;li {display: inline-block;}}}COMPONENT STYLED HTML
  • 23.
    Design and markupare inseparable.Designers and Front-End Engineers must speakubiquitous language to succeed.
  • 24.
    CSS ArchitectureComponents &OtherStylesDependencyManagementPhysical Structure &Deployment
  • 25.
  • 26.
    Goals of ArchitecturePredictableReusableMaintainable Scalable
  • 27.
    Goals of ArchitecturePredictableReusableMaintainable ScalableMinimalComplexity
  • 28.
    “Everyone else inthe W3C CSS Working Group, thegroup which defines the future of CSS, fits the profileof a developer much more than that of a designer.”Lea Verou
  • 29.
  • 30.
    Existing Solutions BEMOOCSS SMACSS Atomic CSS MCSS ITCSS
  • 31.
  • 32.
    #1 DOM IndependencyCSScomponent styles must not rely onparticular DOM structure
  • 33.
  • 34.
    Examplediv.social-links {> diva {color: blue;}} Visual styles are tightly coupled withmarkup which makes them hard toevolve Reusability of component is limited Ambiguity that leads to growth ofspecificity
  • 35.
    RuleAvoid any signsof DOM elements in CSScode including references to HTML tags, ID(#) and (>) child selectors
  • 36.
    RuleCSS selectors mustconvey semantics of thecomponent and it’s integral parts. Classselector conveys a lot, element selectoralmost none
  • 37.
  • 38.
    #2 Location IndependencyCSScomponent styles must not rely oncomponent’s location on a page
  • 39.
  • 40.
    Example.button {color: white;}.sidebar{.button {color: orange;}} Component is no longer self containedentity and its visual appearance is notpredictable at dev time Leads to growth of specificity
  • 41.
    RuleComponent styles mustnot be written inreliance on their location on a page, insteadprovide location independent variations thatcan be used anywhere
  • 42.
    “Instead of saying- The buttons need to be smallerwhen they’re in the header, we need to be saying - Wehave a smaller variant of our buttons, and it’s these thatwe use in the header.”Harry Roberts
  • 43.
    .button {color: white;/*Other declarations */&.button--variant-action {color: orange;}}Example
  • 44.
    #3 Limited ComplexityCSScomponents can be complex and haveintegral parts, but no more than having 1 (2)layers of descendant styles
  • 45.
  • 46.
    Example.filter {.filter__header {.filter__header__icon{/* Declarations */}}.filter__list {.filter__list__link {/* Declarations */}}} Component is too complex whichmakes it hard to maintain Following that style may lead tounnecessary dependencies betweenintegral parts
  • 47.
    RuleIf CSS styleshave no dependency they mustnot form parent-child relationship
  • 48.
    RuleComplex components mustbe split intosimpler components
  • 49.
    .filter {.filter__header {}.filter__icon{/* Declarations */}.filter__list {}.filter__link {/* Declarations */}}Example
  • 50.
    #4 Enforced NamingAllaspects of component definition must be named in away to communicate their relationship clearly andprotect from incorrect use
  • 51.
    .infobox /* Block*/ {.infobox__body /* Element */ {}.infobox__footer {}.infobox__title {}&.infobox--size-full /* Modifier */ {}}Example
  • 52.
    #5 Explicit StatesDynamicbehavior must be implemented with stateclasses that JavaScript toggles. No direct stylemanipulation is allowed with JavaScript.
  • 53.
  • 54.
    open: function (){elements.root.show();elements.trigger.css('color', 'blue');},close: function () {elements.root.hide();elements.trigger.css('color', 'white');}Example Visual appearance of component isnow split across JavaScript and CSSwhich makes is hard to maintain There is no simple undo operationfor setting style properties inJavaScript so previous state has tobe maintained somewhere or inlinestyles manipulated directly
  • 55.
    open: function (){elements.root.addClass('state-open');elements.trigger.addClass('state-active');},close: function () {elements.root.removeClass('state-open');elements.trigger.removeClass('state-active');}Example
  • 56.
    RuleGlobal states mustnot collide with localstates to avoid overrides in CSS
  • 57.
    .state-hidden {display: none;}.infobox{display: inline-block;&.state-hidden {display: inline-block;visibility: hidden;}}Example Component is no longer self containedwhich causes inclusion of overridedeclarations In some cases may lead to a need tohave !importants
  • 58.
    .global-state-hidden {display: none;}.infobox{display: inline-block;&.state-hidden {visibility: hidden;}}Example
  • 59.
    #6 JavaScript HooksNeveruse component classes to select elements withJavaScript. Introduce specialized classes just for thesake of selecting elements.
  • 60.
  • 61.
    Examplevar elements ={mailing_list: internal.$e,form: internal.$e.find('.social-widget__query'),submit_button: internal.$e.find('.button'),submit_button_text: internal.$e.find('span'),validation_message: internal.$e.find('.social-widget__validation-message')}; Hard to modify component styles due to dependencies inJavaScript. Makes whole component fragile
  • 62.
    Example<div class="social-widget social-widget--inversedjs-mailing-list"><div class="social-widget__title">Stay in the loop</div><form class="social-widget__query js-mailing-list-form"><input class="js-mailing-list-email" type="text" name="email" placeholder="Email address"><label class="button"><span class="js-mailing-list-submit-button-text">Submit</span><input class="js-mailing-list-submit-button" type="submit"></label></form><div class="js-mailing-list-validation-message social-widget__validation-message state-hidden">Email is not in correct format!</div></div>
  • 63.
    #7 Local MediaQueriesResponsiveness of a page must be based onresponsiveness of each component thus Media Querymust be local to a component
  • 64.
    .blog-entry {.blog-entry-body {/*Declarations */}}.infobox {}@media @phone {.blog-entry {.blog-entry-body {/* Declarations */}}.infobox {}}Example Code duplication makes componentshard to maintain Components are not self-containedwhich makes the outcome lesspredictable at dev time
  • 65.
    .blog-entry {.blog-entry-body {margin-right:@gutter / 2;margin-bottom: @gutter / 2;margin-left: @gutter / 2;@media @phone {margin-left: @gutter_phone / 2;margin-right: @gutter_phone / 2;}}}Example
  • 66.
    .infobox /* Component*/ {.infobox__body /* Integral Part */ {}&.infobox--size-full /* Variant */ {}&.state-active /* State */ {}@media @phone /* Responsive */ {}}.js-infobox /* JavaScript Hook */Anatomy of Component
  • 67.
    #8 Layout vsVisualLayout aspects should be moved to dedicatedcomponents or integral parts
  • 68.
  • 69.
    .infobox {/* Layout*/float: left;padding-left: @half-col-gutter;padding-right: @half-col-gutter;width: 33.33%;/* Visual */background-color: green;padding: 10px; /* Collision */}Example Limits reusability Usually require additional htmlelements just as styling hooks
  • 70.
    Grid based layoutis an emerging trend in Web andGraphics design
  • 71.
    .grid-row {.clearfix();.grid-row__column {float:left;padding-left: @half-col-gutter;padding-right: @half-col-gutter;width: 33.33%;}}.infobox {background-color: green;padding: 10px;}Example
  • 72.
    #9 Container vsContentContainer components must define layout and sizeconstraints, content components – visual look(occasionally size constraints too)
  • 73.
    RuleDon’t make anyassumptions about contenton container level
  • 74.
    RuleDevelop CSS componentsto be containeragnostic
  • 75.
  • 76.
    Types of StylesBase(Normalize,Reset)Utilities(clearfix, valign)Typography(Fonts, Headings, …)Constants(Colors, Sizes, …)
  • 77.
  • 78.
    Physical StructureSingle fileforall of the stylesSingle file withcommentsOne file pertype of stylesOne file percomponent
  • 79.
    Fallacies Use idselectors for performance reasons Too many classes is a bad thing, style based on tags Nest CSS selectors to follow DOM hierarchy Put all styles into single file all the time because it iseasier to maintain Introduce lots of utility classes to have greater flexibilitywhen styling things
  • 80.
    Thank you!Forward yourquestions toalexei.skachykhin@live.com

Editor's Notes

  • #4 Всё начинается хорошо, но потом становится сложно сопровождать.
  • #7 Второй раз ты пытаешься хорошо писать свойства CSS, но всё равно что-то идёт не так.
  • #10 Interestingly, we don’t usually make this oversight with other languages. A Rails developer isn’t considered good just because his code works to spec. This is considered baseline. Of course it must work to spec; its merit is based on other things: Is the code readable? Is it easy to change or extend? Is it decoupled from other parts of the application? Will it scale?
  • #11 Тут важно сказать что подсознательно первое о чём мы думаем – это то что мы можем работать без плана. Но как было показано на примере это не работает! И дальше пойдёт описание driving forces.
  • #17 Interestingly, we don’t usually make this oversight with other languages. A Rails developer isn’t considered good just because his code works to spec. This is considered baseline. Of course it must work to spec; its merit is based on other things: Is the code readable? Is it easy to change or extend? Is it decoupled from other parts of the application? Will it scale?
  • #27 Требования к CSS архитектуре такие же как и к архитектуре программных компонентов -> Переход на следующий слайд
  • #28 Требования к CSS архитектуре такие же как и к архитектуре программных компонентов -> Переход на следующий слайд

[8]ページ先頭

©2009-2025 Movatter.jp