ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Learning the Cascade
A Better Theme Process
Christopher Cochran
@tweetsfromchris
CSSCascading Style Sheet
Cascading
Order
Media Type Importance Specificity Declaration
all
braille
embossed
handheld
print
projection
@media rules
Media Type Importance Specificity Declaration
screen
speech
tty
tv
Browser
User
Author
User Agent Default Styles
User Customizations
Your Styles
*
*
Media Type Importance Specificity Declaration
Browser
User
Author
User Agent Default Styles
User Customizations
Your Styles
*
*
Media Type Importance Specificity Declaration
Browser
User
Author
User Agent Default Styles
User Customizations
Your Styles
*
*
Media Type Importance Specificity Declaration
Browser
User
Author
User Agent Default Styles
User Customizations
Your Styles
*
*
Media Type Importance Specificity Declaration
!Important
*
Media Type Importance Specificity Declaration
Browser
User
Author
User Agent Default Styles
User !important Customizations
Your !important Styles
Media Type Importance Specificity Declaration
(...but not too specific.)
BE Specific
Media Type Importance Specificity Declaration
Media Type Importance Specificity Declaration
/* Don¡¯t do this */
#content article .entry-header h2.entry-title {
font: 400 1.5em/1.2 Bebas Neue, sans-serif;
}
/* Keep it simple */
.entry-title {
font: 400 1.5em/1.2 Bebas Neue, sans-serif;
}
Media Type Importance Specificity Declaration
#content article .entry-header h2.entry-title {
font: 400 1.5em/1.2 Bebas Neue, sans-serif;
}
To override this...
IS Not FUN!
1. Inline Styles
SPECIFICITY ORDER
Media Type Importance Specificity Declaration
1. Inline Styles
2. IDs
SPECIFICITY ORDER
Media Type Importance Specificity Declaration
1. Inline Styles
2. IDs
3. Classes and pseudo-classes
SPECIFICITY ORDER
Media Type Importance Specificity Declaration
1. Inline Styles
2. IDs
3. Classes and pseudo-classes
4. Elements and pseudo-elements
SPECIFICITY ORDER
Media Type Importance Specificity Declaration
SPECIFICITY ORDER
Media Type Importance Specificity Declaration
* {} /* a=0 b=0 c=0 d=0 -> specificity = 0,0,0,0 */
li {} /* a=0 b=0 c=0 d=1 -> specificity = 0,0,0,1 */
li:first-line {} /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */
ul li {} /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */
ul ol+li {} /* a=0 b=0 c=0 d=3 -> specificity = 0,0,0,3 */
h1 + *[rel=up]{} /* a=0 b=0 c=1 d=1 -> specificity = 0,0,1,1 */
ul ol li.red {} /* a=0 b=0 c=1 d=3 -> specificity = 0,0,1,3 */
li.red.level {} /* a=0 b=0 c=2 d=1 -> specificity = 0,0,2,1 */
#x34y {} /* a=0 b=1 c=0 d=0 -> specificity = 0,1,0,0 */
style="" /* a=1 b=0 c=0 d=0 -> specificity = 1,0,0,0 */
http://www.w3.org/TR/CSS2/cascade.html#specificity
Declaration Order
Media Type Importance Specificity Declaration
body {
color: #bada55;
}
.entry-title {
color: #d0ab1e
}
...
body {
color: #affec7;
}
#affec7
Media Type Importance Specificity Declaration
Body
#d0ab1e
.entry-title
Outcome
Media Type Importance Specificity Declaration
body {
background: #fff;
}
@media (min-width: 760px) {
body {
background: #bada55;
}
}
@media (min-width: 960px) {
body {
background: #affec7;
}
}
Some css values are inherited by the
children of an element in the document
tree.
Inherence
Media Type Importance Specificity Declaration
Media Type Importance Specificity Declaration
body {
font: 16px/1.5 Georgia,Times,"Times New Roman",serif;
color: #222;
}
p {
/* font and color are inherited, and do not need to be
redeclared, unless values need to be changed. */
margin: .625em 0 1.25em;
}
cascade + Inherence =
Media Type Importance Specificity Declaration
(+ Media Queries)
Media Type Importance Specificity Declaration
/* Default styles, applied to all media types. */
body {
/* Base font size */
font: 16px/1.5 Minion Pro, serif;
}
.entry-title {
font: 400 1.5em/1.2 Bebas Neue, sans-serif; /* 24px */
}
@media (min-width: 760px) {
body {
/* Base font size for 760px+ */
font-size: 19px;
}
/* .entry-title = font-size: 29px; */
}
@media (min-width: 960px) {
body {
/* Base font size for 960px+ */
font-size: 18px;
}
/* .entry-title = font-size: 27px; */
}
Flow With The Cascade
It¡¯s a Beautiful Thing
MOBILE FIRST
«þink
MOBILE FIRSTContentFIRST
Cause what exactly is ¡°mobile¡± anyways?
«þink
Start with the Least
Common Denominator
Design from the bottom up;
from the content out.
DON¡¯T display: none;
Don't limit experiences.
Accessible, Lean, Clean, Lightweight
Speed is !important
Performance is Key
(a fundamental component of user experience)
Today¡¯s average website takes 7s to load
Today¡¯s average website takes 7s to load
More than a second will cause the user to interrupt
their flow of thought, creating a poor experience.
Optimize
CSS selectors
Use e?cient
PREPROCESSORS
ARE YOUR FRIEND
SASS, Stylus, LESS
BE MODULAR
«þink in terms of reusable parts to keep
things simple and consistent.
grunt-contrib-concathttps://github.com/gruntjs/grunt-contrib-concat
Combine multiple files into one output file
grunt-contrib-cssminhttps://github.com/gruntjs/grunt-contrib-cssmin
Minify CSS files
TEST, TEST, TEST
TEST
Don¡¯t just test Browsers, and Devices,
But loading on different connectivity
Definitely check out Network Link Conditioner for OS X
Q&A
«þanks!

More Related Content

A Better Theme Process: Learning the Cascade