A Better Theme Process: Learning the Cascade

45
Learning the Cascade A Better Theme Process Christopher Cochran @tweetsfromchris

description

WPSessions WordPress Theme Bootcamp: A Better Theme Process - Learning the Cascade. Learn how to utilize the cascading nature of CSS to your benefit, in creating a mobile first content focused theme.

Transcript of A Better Theme Process: Learning the Cascade

Page 1: A Better Theme Process: Learning the Cascade

Learning the CascadeA Better Theme Process

Christopher Cochran@tweetsfromchris

Page 2: A Better Theme Process: Learning the Cascade

CSSCascading Style Sheet

Page 3: A Better Theme Process: Learning the Cascade

CascadingOrder

Media Type Importance Speci!city Declaration

Page 4: A Better Theme Process: Learning the Cascade

allbrailleembossedhandheldprintprojection

@media rules

Media Type Importance Speci!city Declaration

screenspeechttytv

Page 5: A Better Theme Process: Learning the Cascade

Browser

User

Author

User Agent Default Styles

User Customizations

Your Styles

*

*

Media Type Importance Speci!city Declaration

Page 6: A Better Theme Process: Learning the Cascade

Browser

User

Author

User Agent Default Styles

User Customizations

Your Styles

*

*

Media Type Importance Speci!city Declaration

Page 7: A Better Theme Process: Learning the Cascade

Browser

User

Author

User Agent Default Styles

User Customizations

Your Styles

*

*

Media Type Importance Speci!city Declaration

Page 8: A Better Theme Process: Learning the Cascade

Browser

User

Author

User Agent Default Styles

User Customizations

Your Styles

*

*

Media Type Importance Speci!city Declaration

Page 9: A Better Theme Process: Learning the Cascade

!Important*

Media Type Importance Speci!city Declaration

Page 10: A Better Theme Process: Learning the Cascade

Browser

User

AuthorUser Agent Default Styles

User !important Customizations

Your !important Styles

Media Type Importance Speci!city Declaration

Page 11: A Better Theme Process: Learning the Cascade

(...but not too speci!c.)BE Specific

Media Type Importance Speci!city Declaration

Page 12: A Better Theme Process: Learning the Cascade

Media Type Importance Speci!city 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; }

Page 13: A Better Theme Process: Learning the Cascade

Media Type Importance Speci!city Declaration

#content article .entry-header h2.entry-title { font: 400 1.5em/1.2 Bebas Neue, sans-serif; }

To override this...

IS Not FUN!

Page 14: A Better Theme Process: Learning the Cascade

1. Inline Styles

SPECIFICITY ORDER

Media Type Importance Speci!city Declaration

Page 15: A Better Theme Process: Learning the Cascade

1. Inline Styles2. IDs

SPECIFICITY ORDER

Media Type Importance Speci!city Declaration

Page 16: A Better Theme Process: Learning the Cascade

1. Inline Styles2. IDs3. Classes and pseudo-classes

SPECIFICITY ORDER

Media Type Importance Speci!city Declaration

Page 17: A Better Theme Process: Learning the Cascade

1. Inline Styles2. IDs3. Classes and pseudo-classes4. Elements and pseudo-elements

SPECIFICITY ORDER

Media Type Importance Speci!city Declaration

Page 18: A Better Theme Process: Learning the Cascade

SPECIFICITY ORDER

Media Type Importance Speci!city 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#speci!city

Page 19: A Better Theme Process: Learning the Cascade

Declaration Order

Media Type Importance Speci!city Declaration

body { color: #bada55; }

.entry-title { color: #d0ab1e }

...

body { color: #affec7; }

Page 20: A Better Theme Process: Learning the Cascade

#affec7

Media Type Importance Speci!city Declaration

Body

#d0ab1e.entry-title

Outcome

Page 21: A Better Theme Process: Learning the Cascade

Media Type Importance Speci!city Declaration

body { background: #fff; }

@media (min-width: 760px) { body { background: #bada55; } } @media (min-width: 960px) { body { background: #affec7; } }

Page 22: A Better Theme Process: Learning the Cascade

Some css values are inherited by the children of an element in the document tree.

Inherence

Media Type Importance Speci!city Declaration

Page 23: A Better Theme Process: Learning the Cascade

Media Type Importance Speci!city 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; }

Page 24: A Better Theme Process: Learning the Cascade

cascade + Inherence =

Media Type Importance Speci!city Declaration

(+ Media Queries)

Page 25: A Better Theme Process: Learning the Cascade

Media Type Importance Speci!city 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; */ }

Page 26: A Better Theme Process: Learning the Cascade

Flow With The CascadeIt’s a Beautiful Thing

Page 27: A Better Theme Process: Learning the Cascade

MOBILE FIRSTink

Page 28: A Better Theme Process: Learning the Cascade

MOBILE FIRSTContentFIRSTCause what exactly is “mobile” anyways?

ink

Page 29: A Better Theme Process: Learning the Cascade

Start with the LeastCommon Denominator

Page 30: A Better Theme Process: Learning the Cascade

Design from the bottom up; from the content out.

Page 31: A Better Theme Process: Learning the Cascade

DON’T display: none;Don't limit experiences.

Page 32: A Better Theme Process: Learning the Cascade

Accessible, Lean, Clean, Lightweight

Page 33: A Better Theme Process: Learning the Cascade

Speed is !importantPerformance is Key

(a fundamental component of user experience)

Page 34: A Better Theme Process: Learning the Cascade

Today’s average website takes 7s to load

Page 35: A Better Theme Process: Learning the Cascade

Today’s average website takes 7s to load

More than a second will cause the user to interrupt their "ow of thought, creating a poor experience.

Page 36: A Better Theme Process: Learning the Cascade

Optimize

Page 37: A Better Theme Process: Learning the Cascade

CSS selectorsUse efficient

Page 38: A Better Theme Process: Learning the Cascade

PREPROCESSORS ARE YOUR FRIEND

SASS, Stylus, LESS

Page 39: A Better Theme Process: Learning the Cascade

BE MODULARink in terms of reusable parts to keep

things simple and consistent.

Page 40: A Better Theme Process: Learning the Cascade

grunt-contrib-concathttps://github.com/gruntjs/grunt-contrib-concat

Combine multiple #les into one output #le

Page 41: A Better Theme Process: Learning the Cascade

grunt-contrib-cssminhttps://github.com/gruntjs/grunt-contrib-cssmin

Minify CSS #les

Page 42: A Better Theme Process: Learning the Cascade

TEST, TEST, TEST

Page 43: A Better Theme Process: Learning the Cascade

TEST

Page 44: A Better Theme Process: Learning the Cascade

Don’t just test Browsers, and Devices,But loading on different connectivity

De!nitely check out Network Link Conditioner for OS X

Page 45: A Better Theme Process: Learning the Cascade

Q&Aanks!