SlideShare a Scribd company logo
Scalable 
CSS 
(That both you and your ‘back-end’ coders can love.) 
! 
about.me/XML #xmlilley
UI DEV HAS GOTTEN COOL !!!?!
“… an anti-language, 
full of dark magic…” 
-my really smart colleague
WHYYYYYY????? 
And why do we care?
I asked them. And they said 
it’s all about … 
The whole ‘Cascading’ thing 
The ‘Specificity’ thing 
(see also: ‘the Cascading thing’) 
Selector Chaos 
(mostly re: Specificity & Cascading) 
Layout 
(old-school Layouts, that is…)
Hmmmmm….
Option 1: 
They must need better 
training about this stuff
Option 2: 
Maybe they’ve got a point.
“If all you’ve got 
is a hammer, 
everything looks 
like a nail.”
(See also: 
“Stockholm 
Syndrome”)
First Principles 
be DRY - ‘Don’t Repeat Yourself’ 
be Maintainable - write for updates & 
debugging 
be Predictable - Don’t keep hacking what’s 
broken (unless you have to) 
Don’t ‘Optimize’ Prematurely
Strategic Rules For CSS 
Name All The Things™ 
Stop Hoarding Classes 
& Rationing Letters 
Be a Lover, not a Fighter 
Automate or Die
Challenge 1: 
Use Layouts That 
Make Sense
The Super-Secret Key to 
Eliminating 99% of Layout Angst 
STOP 
USING 
FLOAT: 
ALREADY !!!!
Instead of this: 
Or this:
Or worse, this (which is unfixable in code): 
#3 #2 #1 
You get this:
Stop Fighting With 
Floats 
!
Love Display: Inline-Block 
Supported Since IE8 !!! 
Does what you expect 
vertical-align: a feature, not a bug :-) 
text-align: gets you left, right, or 
center
Love Display: Inline-Block 
(The whitespace thing *is* a bug. 
Easy, transparent fix: zero-sized 
fonts on the container. 
Use @mixin !)
Display: Inline-Block (Coda) 
Those deceptively-reasonable .clearfix 
classes that don’t need extra HTML? 
They need :after … 
… which requires CSS 2.1 … 
… which has display: inline-block
Bonus Confusing Layout Idol 
To Consider Burning 
Ems 
(Browser scaling works great) 
(In practice, people use a range of 
assistive technologies, and very 
rarely rely on custom stylesheets.)
Challenge 2: 
Make CSS Code 
Maintainable
Where we *think* 
we spend all our time: 
TYPING
Where we *actually* 
spend all our time: 
1. READING 
2. TRYING to understand 
3. RE-reading 
4. MIS-understanding 
5. Revert to: Step 1
“Maintainability” === 
OPTIMIZE FIRST FOR 
THE PROCESSOR 
INSIDE YOUR SKULL
“In God, we trust. 
All others: 
bring evidence.”
OK… Maintainability… How? 
1. AUTOMATE (OR DIE) 
2. “NAME ALL THE THINGS”… CLEARLY 
3. USE ELEMENT SELECTORS ONLY FOR RESETS 
4. STOP OVER-NESTING… OR MAYBE NESTING 
*AT ALL* 
5. AVOID UNNECESSARY COMPLEXITY
Maintainability… How? 
1. AUTOMATE (OR DIE) 
2. “NAME ALL THE THINGS”… CLEARLY 
3. USE ELEMENT SELECTORS ONLY FOR RESETS 
4. STOP OVER-NESTING… OR MAYBE NESTING 
*AT ALL* 
5. AVOID UNNECESSARY COMPLEXITY
AUTOMATION 
Enough with the FUD. It’s easier than you think. 
Just use a (pre-)compiler. Always. (See Yeoman for help.) 
A new age is upon us. 
There is literally not enough time in this session to detail 
all the ways in which a compiler will make your CSS 
better. 
But here’s a few: you’ve heard about ‘variables’ and 
‘mixins’, but not *why* you need them:
AUTOMATION Examples: 
Human-Readable Colors 
Stop working directly with color codes! Use human-readable 
references like $brand-primary-highlight 
or $ugly-greenish-blue. 
Lighten, Darken, Opacify, Transparentize, using a single 
original reference color. Make a whole chart w/: 
color: $myRed 
$redTwo: darken($myRed, 10%) 
$redThree: darken($myRed, 20%)… 
‘Theme’ a design with just a few variables, and @import
AUTOMATION Example: 
Easy Responsive 
#key-component__guide-text { 
@include apply-at-max-size { 
width:78%; 
} 
@include apply-at-med-size { 
width: 50%; 
} 
@include disappear-at-sm-size; 
}
AUTOMATION Example: 
Easy Responsive 
@mixin apply-at-max-size { 
@media (min-width: $screen-md-min + 1) { 
@content; 
}} 
@mixin apply-at-med-max-size { 
@media (min-width: $screen-sm-min) { 
@content; 
}} 
@mixin disappear-at-sm-size { 
@include apply-at-sm-size { 
display: none; 
}}
AUTOMATION Example: 
Easy Responsive 
$screen-xs-min: 320px; 
$screen-sm-min: 550px; 
$screen-md-min: 768px; 
…etc.
MOAR AUTOMATION 
Browser prefixes suck. Use either @mixin’s… or Grunt! 
Easy theming: take theme-specific variables & @mixin’s, 
then @import your default rules, and voilà!
Maintainability… How? 
1. AUTOMATE (OR DIE) 
2. “NAME ALL THE THINGS”… CLEARLY 
3. USE ELEMENT SELECTORS ONLY FOR RESETS 
4. STOP OVER-NESTING… OR MAYBE NESTING 
*AT ALL* 
5. AVOID UNNECESSARY COMPLEXITY
Who was it who told us that this: 
#nav-list li a { 
… stuff… 
} 
… was a good idea? Instead of this: 
.nav-list-link { 
… same stuff … 
} 
… or better… this: 
.main-header__nav-list__link { 
… same stuff … 
}
Stop Rationing Classes! 
It’s as if we were afraid that classes were radioactive: 
too many, too close together, and they’d go super-critical 
Or as if they were contaminating our pristine HTML 
We also like to feel clever. (Be afraid of that instinct.) 
Classes are as efficient as it gets, speed-wise.
Use Clear, Descriptive Classes 
It shouldn’t be necessary to hunt for things. Class names 
should tell us where to expect to find things. 
Sometimes, the hardest thing about using good names is 
just inventing ones that make sense. 
Use any system you like (BEM, OOCS, Suit), which is both 
highly descriptive, and which helps you design good class 
names. 
(Remember they’re helpful patterns, not religious faiths.)
A Note on Namespacing 
As a way of collecting a ‘module’ of related content or 
functionality, namespacing is super-cool. 
But it quickly goes fractal with automation. 
Consider whether using detailed, descriptive class 
names gets you what you were probably really after: 
the avoidance of collisions. 
(See the section on over-nesting.)
Maintainability… How? 
1. AUTOMATE (OR DIE) 
2. “NAME ALL THE THINGS”… CLEARLY 
3. USE ELEMENT SELECTORS ONLY FOR RESETS 
4. STOP OVER-NESTING… OR MAYBE NESTING 
*AT ALL* 
5. AVOID UNNECESSARY COMPLEXITY
About That Whole 
‘Cascade’ Thing 
No matter how much we explain it, the ‘back-end’ folks 
will never understand why we would allow five different 
user-created style declarations to apply to a single 
element 
They’re right: it’s not maintainable. 
The “browser is designed that way” isn’t a good enough 
reason. 
We *can* do that, but we *shouldn’t*.
About That Whole 
‘Cascade’ Thing 
Element selectors are the number one reason we end up 
fighting the cascade, and hoping that the Specificity 
algorithm is on our side today. 
You don’t need them. 
One good use: resets and global styles, like: 
a { 
text-decoration: none; 
color: red; 
}
About That Whole 
‘Cascade’ Thing 
Use of !important is always a “code-smell” 
Maybe use @extend or @include to create a narrower 
class, rather than fight the existing one 
“Be a lover, not a fighter”
Maintainability… How? 
1. AUTOMATE (OR DIE) 
2. “NAME ALL THE THINGS”… CLEARLY 
3. USE ELEMENT SELECTORS ONLY FOR RESETS 
4. STOP OVER-NESTING… OR MAYBE NESTING 
*AT ALL* 
5. AVOID UNNECESSARY COMPLEXITY
Descendant Selectors: 
The Problems 
General use of descendant selectors is anathema to real 
specificity, and guarantees conflicts and overrides: 
form label input 
#login-form input .name-field 
! 
Descendant Selectors lock your content into a single 
context, making them hard to re-use, or re-locate. 
Plus, you can’t relocate other code into yours: ever try to 
add a JQuery date-picker into code that’s styled with 
descendant selectors?
Pre-Compilers Gone Wrong 
body { 
font-size: 12px; 
#main-content: { 
width: 400px; 
height: 200px; 
! 
.left-nav { 
width: 200px; 
margin: 0 0 0 50px; 
! 
ul { 
li { 
display: block; 
list-style-type: none; 
… ∞ … 
}}}}} 
body #main .left-nav ul li … 
5 selectors and counting, 
where 1 would do it.
Descendant Selectors: 
Performance 
The most important thing you can know about selector 
optimization is this: they’re evaluated right-to-left. 
The most important piece of any selector is thus the last 
piece, not the first. Which is pretty much the opposite of 
what we usually do with descendant selectors: 
#very-specific-id .semi-specific-class li a 
The fact that we *can* nest and qualify selectors… 
doesn’t mean that we *should*.
Nesting Without Stacking 
A (pre-)compiler w/ BEM-like syntax gives us readability of 
related styles, without descendant-selector headaches: 
.main-content: { 
&__left-nav { 
&__item 
}}} 
compiles to: 
.main-content {} 
.main-content__left-nav {} 
.main-content__left-nav__item {} 
(If you don’t like those syntaxes, at least just use indentation 
instead of nesting.)
Nesting & Stacking 
Rule of thumb: nest selectors and stack classes when 
you *have to*, not just when you *can*. 
Rule of thumb: nest and stack your @mixin’s and 
@extend’s, not your selectors. 
@mixin body-text { 
color: green; 
font: { 
size: 14px; 
family: Arial; 
} } 
@mixin nav-list__item { 
line-spacing: 1; 
list-style-type: none; 
display: inline-block; 
vertical-align: top; 
} 
.header__nav-list__item { 
@include body-text; 
@include nav-list__item; 
padding: 5px; 
}
Nesting & Stacking 
Relying on @mixin and @extend with descriptive 
classes, rather than on stacked, generic classes means 
that refactoring is easy, and overrides (if necessary) 
happen where you can see them, and plan them: in your 
code. 
If it comes time to refactor for performance, your most-used 
mixins can easily convert to standalone classes. 
Going the other direction… not so much.
Stacking Classes: Pros & Cons 
Stacking (<div class=“class1 class2”) is great if you can’t 
re-write your classes (ie. Bootstrap, components) 
Stacking is declarative, at least in your HTML 
It’s not at all declarative back in the CSS, forcing us to use 
the Dev Tools’ Style Inspector to see what happens 
It puts you into ‘fighting’ mode: overriding the conflicts 
For Optimization: use tactically, not strategically
Stacking Classes: Pros & Cons 
A Thought: how many of the reasons why we stack our 
classes are because we didn’t have pre-compilers back 
when we started doing it?
Maintainability… How? 
1. AUTOMATE (OR DIE) 
2. “NAME ALL THE THINGS”… CLEARLY 
3. USE ELEMENT SELECTORS ONLY FOR RESETS 
4. STOP OVER-NESTING… OR MAYBE NESTING 
*AT ALL* 
5. AVOID UNNECESSARY COMPLEXITY
Don’t Fight Your Elements 
Do you really know if <section>, <article>, etc. do 
anything for you? (hint: they don’t) Use them only if 
they’re helpful in some human-readable way. 
Don’t feel guilty! The era of semantic *elements* for 
machine-readability is largely over, in favor of semantic 
*attributes*. See: WAI-ARIA, microformats
Don’t Fight Your Elements 
Use the most flexible elements available; ones you can 
rearrange and refactor without breaking them. 
Just because some content is vaguely ‘tabular’ in nature 
doesn’t mean you *have* to use a <table>. You can’t scroll 
the <tbody>, and styling is painful. So, don’t do it. 
Just because somebody once said that <ul> is more 
‘semantic’ than <div> for navigation items doesn’t mean it’s 
still worth fighting with it (particularly now that we have 
<nav>) Does it *look like* a list? No? Then don’t.
Pseudo-Helpful 
When you don’t control a template, and can’t assign 
classes, pseudo-selectors are great. Otherwise, maybe not. 
Expensive for what you get. 
Are there other options? Can Javascript help? For example, 
would using Angular’s $first and $last maybe work *at 
least* as well as :first-child/:last-child? 
(Remember: a new age is upon us.)
THANKS! 
(Now go teach those ‘back-end’ folks some tricks.) 
! 
about.me/XML #xmlilley

More Related Content

What's hot

REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
Building AngularJS Custom Directives
Building AngularJS Custom DirectivesBuilding AngularJS Custom Directives
Building AngularJS Custom Directives
Dan Wahlin
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
Stijn Van Minnebruggen
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
Bert Wijnants
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
Addy Osmani
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
Isfand yar Khan
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
Yourcontent YC
 
jQuery
jQueryjQuery
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directives
yprodev
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
Asya Dudnik
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
Kamal S
 
React
React React
React
중운 박
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
chandrashekher786
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
All Things Open
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
Luther Baker
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
Rod Johnson
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jquery
Umar Ali
 

What's hot (19)

REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScript
 
Building AngularJS Custom Directives
Building AngularJS Custom DirectivesBuilding AngularJS Custom Directives
Building AngularJS Custom Directives
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 
jQuery
jQueryjQuery
jQuery
 
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directives
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
React
React React
React
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jquery
 

Similar to Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014

CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
William Myers
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
Nicole Sullivan
 
Creative Web 02 - HTML & CSS Basics
Creative Web 02 - HTML & CSS BasicsCreative Web 02 - HTML & CSS Basics
Creative Web 02 - HTML & CSS Basics
Lukas Oppermann
 
CSS_tutorial_2
CSS_tutorial_2CSS_tutorial_2
CSS_tutorial_2
tutorialsruby
 
CSS_tutorial_2
CSS_tutorial_2CSS_tutorial_2
CSS_tutorial_2
tutorialsruby
 
Aem best practices
Aem best practicesAem best practices
Aem best practices
Jitendra Tomar
 
CSS 101
CSS 101CSS 101
CSS 101
dunclair
 
CSS pattern libraries
CSS pattern librariesCSS pattern libraries
CSS pattern libraries
Russ Weakley
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Dominate The Theme Layer
Dominate The Theme LayerDominate The Theme Layer
Dominate The Theme Layer
Jesper Wøldiche
 
CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
Russ Weakley
 
CSS Frameworks
CSS FrameworksCSS Frameworks
CSS Frameworks
Mike Crabb
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
Arash Manteghi
 
Sass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LASass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LA
Jake Johnson
 
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
Sanjoy Kr. Paul
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
Maxim Vialyx
 
On Coding Guidelines
On Coding GuidelinesOn Coding Guidelines
On Coding Guidelines
DIlawar Singh
 
Dependency Injection for PHP
Dependency Injection for PHPDependency Injection for PHP
Dependency Injection for PHP
mtoppa
 
Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
William Myers
 

Similar to Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014 (20)

CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
 
Creative Web 02 - HTML & CSS Basics
Creative Web 02 - HTML & CSS BasicsCreative Web 02 - HTML & CSS Basics
Creative Web 02 - HTML & CSS Basics
 
CSS_tutorial_2
CSS_tutorial_2CSS_tutorial_2
CSS_tutorial_2
 
CSS_tutorial_2
CSS_tutorial_2CSS_tutorial_2
CSS_tutorial_2
 
Aem best practices
Aem best practicesAem best practices
Aem best practices
 
CSS 101
CSS 101CSS 101
CSS 101
 
CSS pattern libraries
CSS pattern librariesCSS pattern libraries
CSS pattern libraries
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
 
Dominate The Theme Layer
Dominate The Theme LayerDominate The Theme Layer
Dominate The Theme Layer
 
CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
 
CSS Frameworks
CSS FrameworksCSS Frameworks
CSS Frameworks
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
 
Sass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LASass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LA
 
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
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
On Coding Guidelines
On Coding GuidelinesOn Coding Guidelines
On Coding Guidelines
 
Dependency Injection for PHP
Dependency Injection for PHPDependency Injection for PHP
Dependency Injection for PHP
 
Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
 

Recently uploaded

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 

Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014

  • 1. Scalable CSS (That both you and your ‘back-end’ coders can love.) ! about.me/XML #xmlilley
  • 2. UI DEV HAS GOTTEN COOL !!!?!
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. “… an anti-language, full of dark magic…” -my really smart colleague
  • 8.
  • 9. WHYYYYYY????? And why do we care?
  • 10.
  • 11.
  • 12.
  • 13. I asked them. And they said it’s all about … The whole ‘Cascading’ thing The ‘Specificity’ thing (see also: ‘the Cascading thing’) Selector Chaos (mostly re: Specificity & Cascading) Layout (old-school Layouts, that is…)
  • 15. Option 1: They must need better training about this stuff
  • 16.
  • 17. Option 2: Maybe they’ve got a point.
  • 18. “If all you’ve got is a hammer, everything looks like a nail.”
  • 19. (See also: “Stockholm Syndrome”)
  • 20. First Principles be DRY - ‘Don’t Repeat Yourself’ be Maintainable - write for updates & debugging be Predictable - Don’t keep hacking what’s broken (unless you have to) Don’t ‘Optimize’ Prematurely
  • 21. Strategic Rules For CSS Name All The Things™ Stop Hoarding Classes & Rationing Letters Be a Lover, not a Fighter Automate or Die
  • 22. Challenge 1: Use Layouts That Make Sense
  • 23. The Super-Secret Key to Eliminating 99% of Layout Angst STOP USING FLOAT: ALREADY !!!!
  • 24.
  • 25. Instead of this: Or this:
  • 26. Or worse, this (which is unfixable in code): #3 #2 #1 You get this:
  • 27. Stop Fighting With Floats !
  • 28. Love Display: Inline-Block Supported Since IE8 !!! Does what you expect vertical-align: a feature, not a bug :-) text-align: gets you left, right, or center
  • 29. Love Display: Inline-Block (The whitespace thing *is* a bug. Easy, transparent fix: zero-sized fonts on the container. Use @mixin !)
  • 30. Display: Inline-Block (Coda) Those deceptively-reasonable .clearfix classes that don’t need extra HTML? They need :after … … which requires CSS 2.1 … … which has display: inline-block
  • 31. Bonus Confusing Layout Idol To Consider Burning Ems (Browser scaling works great) (In practice, people use a range of assistive technologies, and very rarely rely on custom stylesheets.)
  • 32. Challenge 2: Make CSS Code Maintainable
  • 33. Where we *think* we spend all our time: TYPING
  • 34. Where we *actually* spend all our time: 1. READING 2. TRYING to understand 3. RE-reading 4. MIS-understanding 5. Revert to: Step 1
  • 35. “Maintainability” === OPTIMIZE FIRST FOR THE PROCESSOR INSIDE YOUR SKULL
  • 36. “In God, we trust. All others: bring evidence.”
  • 37. OK… Maintainability… How? 1. AUTOMATE (OR DIE) 2. “NAME ALL THE THINGS”… CLEARLY 3. USE ELEMENT SELECTORS ONLY FOR RESETS 4. STOP OVER-NESTING… OR MAYBE NESTING *AT ALL* 5. AVOID UNNECESSARY COMPLEXITY
  • 38. Maintainability… How? 1. AUTOMATE (OR DIE) 2. “NAME ALL THE THINGS”… CLEARLY 3. USE ELEMENT SELECTORS ONLY FOR RESETS 4. STOP OVER-NESTING… OR MAYBE NESTING *AT ALL* 5. AVOID UNNECESSARY COMPLEXITY
  • 39. AUTOMATION Enough with the FUD. It’s easier than you think. Just use a (pre-)compiler. Always. (See Yeoman for help.) A new age is upon us. There is literally not enough time in this session to detail all the ways in which a compiler will make your CSS better. But here’s a few: you’ve heard about ‘variables’ and ‘mixins’, but not *why* you need them:
  • 40. AUTOMATION Examples: Human-Readable Colors Stop working directly with color codes! Use human-readable references like $brand-primary-highlight or $ugly-greenish-blue. Lighten, Darken, Opacify, Transparentize, using a single original reference color. Make a whole chart w/: color: $myRed $redTwo: darken($myRed, 10%) $redThree: darken($myRed, 20%)… ‘Theme’ a design with just a few variables, and @import
  • 41. AUTOMATION Example: Easy Responsive #key-component__guide-text { @include apply-at-max-size { width:78%; } @include apply-at-med-size { width: 50%; } @include disappear-at-sm-size; }
  • 42. AUTOMATION Example: Easy Responsive @mixin apply-at-max-size { @media (min-width: $screen-md-min + 1) { @content; }} @mixin apply-at-med-max-size { @media (min-width: $screen-sm-min) { @content; }} @mixin disappear-at-sm-size { @include apply-at-sm-size { display: none; }}
  • 43. AUTOMATION Example: Easy Responsive $screen-xs-min: 320px; $screen-sm-min: 550px; $screen-md-min: 768px; …etc.
  • 44. MOAR AUTOMATION Browser prefixes suck. Use either @mixin’s… or Grunt! Easy theming: take theme-specific variables & @mixin’s, then @import your default rules, and voilà!
  • 45. Maintainability… How? 1. AUTOMATE (OR DIE) 2. “NAME ALL THE THINGS”… CLEARLY 3. USE ELEMENT SELECTORS ONLY FOR RESETS 4. STOP OVER-NESTING… OR MAYBE NESTING *AT ALL* 5. AVOID UNNECESSARY COMPLEXITY
  • 46. Who was it who told us that this: #nav-list li a { … stuff… } … was a good idea? Instead of this: .nav-list-link { … same stuff … } … or better… this: .main-header__nav-list__link { … same stuff … }
  • 47. Stop Rationing Classes! It’s as if we were afraid that classes were radioactive: too many, too close together, and they’d go super-critical Or as if they were contaminating our pristine HTML We also like to feel clever. (Be afraid of that instinct.) Classes are as efficient as it gets, speed-wise.
  • 48. Use Clear, Descriptive Classes It shouldn’t be necessary to hunt for things. Class names should tell us where to expect to find things. Sometimes, the hardest thing about using good names is just inventing ones that make sense. Use any system you like (BEM, OOCS, Suit), which is both highly descriptive, and which helps you design good class names. (Remember they’re helpful patterns, not religious faiths.)
  • 49. A Note on Namespacing As a way of collecting a ‘module’ of related content or functionality, namespacing is super-cool. But it quickly goes fractal with automation. Consider whether using detailed, descriptive class names gets you what you were probably really after: the avoidance of collisions. (See the section on over-nesting.)
  • 50. Maintainability… How? 1. AUTOMATE (OR DIE) 2. “NAME ALL THE THINGS”… CLEARLY 3. USE ELEMENT SELECTORS ONLY FOR RESETS 4. STOP OVER-NESTING… OR MAYBE NESTING *AT ALL* 5. AVOID UNNECESSARY COMPLEXITY
  • 51. About That Whole ‘Cascade’ Thing No matter how much we explain it, the ‘back-end’ folks will never understand why we would allow five different user-created style declarations to apply to a single element They’re right: it’s not maintainable. The “browser is designed that way” isn’t a good enough reason. We *can* do that, but we *shouldn’t*.
  • 52. About That Whole ‘Cascade’ Thing Element selectors are the number one reason we end up fighting the cascade, and hoping that the Specificity algorithm is on our side today. You don’t need them. One good use: resets and global styles, like: a { text-decoration: none; color: red; }
  • 53. About That Whole ‘Cascade’ Thing Use of !important is always a “code-smell” Maybe use @extend or @include to create a narrower class, rather than fight the existing one “Be a lover, not a fighter”
  • 54. Maintainability… How? 1. AUTOMATE (OR DIE) 2. “NAME ALL THE THINGS”… CLEARLY 3. USE ELEMENT SELECTORS ONLY FOR RESETS 4. STOP OVER-NESTING… OR MAYBE NESTING *AT ALL* 5. AVOID UNNECESSARY COMPLEXITY
  • 55. Descendant Selectors: The Problems General use of descendant selectors is anathema to real specificity, and guarantees conflicts and overrides: form label input #login-form input .name-field ! Descendant Selectors lock your content into a single context, making them hard to re-use, or re-locate. Plus, you can’t relocate other code into yours: ever try to add a JQuery date-picker into code that’s styled with descendant selectors?
  • 56. Pre-Compilers Gone Wrong body { font-size: 12px; #main-content: { width: 400px; height: 200px; ! .left-nav { width: 200px; margin: 0 0 0 50px; ! ul { li { display: block; list-style-type: none; … ∞ … }}}}} body #main .left-nav ul li … 5 selectors and counting, where 1 would do it.
  • 57. Descendant Selectors: Performance The most important thing you can know about selector optimization is this: they’re evaluated right-to-left. The most important piece of any selector is thus the last piece, not the first. Which is pretty much the opposite of what we usually do with descendant selectors: #very-specific-id .semi-specific-class li a The fact that we *can* nest and qualify selectors… doesn’t mean that we *should*.
  • 58. Nesting Without Stacking A (pre-)compiler w/ BEM-like syntax gives us readability of related styles, without descendant-selector headaches: .main-content: { &__left-nav { &__item }}} compiles to: .main-content {} .main-content__left-nav {} .main-content__left-nav__item {} (If you don’t like those syntaxes, at least just use indentation instead of nesting.)
  • 59. Nesting & Stacking Rule of thumb: nest selectors and stack classes when you *have to*, not just when you *can*. Rule of thumb: nest and stack your @mixin’s and @extend’s, not your selectors. @mixin body-text { color: green; font: { size: 14px; family: Arial; } } @mixin nav-list__item { line-spacing: 1; list-style-type: none; display: inline-block; vertical-align: top; } .header__nav-list__item { @include body-text; @include nav-list__item; padding: 5px; }
  • 60. Nesting & Stacking Relying on @mixin and @extend with descriptive classes, rather than on stacked, generic classes means that refactoring is easy, and overrides (if necessary) happen where you can see them, and plan them: in your code. If it comes time to refactor for performance, your most-used mixins can easily convert to standalone classes. Going the other direction… not so much.
  • 61. Stacking Classes: Pros & Cons Stacking (<div class=“class1 class2”) is great if you can’t re-write your classes (ie. Bootstrap, components) Stacking is declarative, at least in your HTML It’s not at all declarative back in the CSS, forcing us to use the Dev Tools’ Style Inspector to see what happens It puts you into ‘fighting’ mode: overriding the conflicts For Optimization: use tactically, not strategically
  • 62. Stacking Classes: Pros & Cons A Thought: how many of the reasons why we stack our classes are because we didn’t have pre-compilers back when we started doing it?
  • 63. Maintainability… How? 1. AUTOMATE (OR DIE) 2. “NAME ALL THE THINGS”… CLEARLY 3. USE ELEMENT SELECTORS ONLY FOR RESETS 4. STOP OVER-NESTING… OR MAYBE NESTING *AT ALL* 5. AVOID UNNECESSARY COMPLEXITY
  • 64. Don’t Fight Your Elements Do you really know if <section>, <article>, etc. do anything for you? (hint: they don’t) Use them only if they’re helpful in some human-readable way. Don’t feel guilty! The era of semantic *elements* for machine-readability is largely over, in favor of semantic *attributes*. See: WAI-ARIA, microformats
  • 65. Don’t Fight Your Elements Use the most flexible elements available; ones you can rearrange and refactor without breaking them. Just because some content is vaguely ‘tabular’ in nature doesn’t mean you *have* to use a <table>. You can’t scroll the <tbody>, and styling is painful. So, don’t do it. Just because somebody once said that <ul> is more ‘semantic’ than <div> for navigation items doesn’t mean it’s still worth fighting with it (particularly now that we have <nav>) Does it *look like* a list? No? Then don’t.
  • 66. Pseudo-Helpful When you don’t control a template, and can’t assign classes, pseudo-selectors are great. Otherwise, maybe not. Expensive for what you get. Are there other options? Can Javascript help? For example, would using Angular’s $first and $last maybe work *at least* as well as :first-child/:last-child? (Remember: a new age is upon us.)
  • 67. THANKS! (Now go teach those ‘back-end’ folks some tricks.) ! about.me/XML #xmlilley