DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified and Scalable stylesheets

Jer Clarke
Jer ClarkeCode Unicorn (WordPress) at Global Voices
DRY CSS
A DON’T-REPEAT-YOURSELF METHODOLOGY
  FOR CREATING EFFICIENT, UNIFIED AND
         SCALABLE STYLESHEETS

    Jeremy Clarke • http://jeremyclarke.org
                 Download these slides:
        http://slideshare.net/jeremyclarke
WHO IS JEREMY CLARKE?


• Communications   Studies at Concordia
 University.

• HTML+CSS     since 2003

• Montreal WordPress
                  Community/
 WordCamp organizer.
OVERVIEW
• An   example of DRY CSS, Global Voices.

• DRY   principle and problems with CSS.

• Preparsers   (LESS and SASS) and their issues.

• DRY   CSS theory, implementation and benefits.

• Appendix: OOCSS
DRY EXAMPLE: GLOBAL VOICES
DRY EXAMPLE: GLOBAL VOICES
                               Before DRY CSS       After DRY CSS


• Applying DRY reduced 4200                                     5,000

 lines to 2400.
                                                               3,750
• Standardized  Shapes, text
 sizes, colors and modules.                                    2,500


                                                            1,250
• Nothinglost, just better
 organized.                                                0
                                     Lines of CSS
DRY EXAMPLE: GLOBAL VOICES

• Groups define shared
 properties.

• Groups   have many selectors.

• Each
     property/value pair is
 defined only once.
DRY EXAMPLE: GLOBAL VOICES
   #ROUNDED5-BORDER2
                  #MEDIUM-ORANGE-TEXT




#PALE-GREY-BACKGROUND
                      #GREY-BUTTON
                    #GREY-BUTTON-HOVER
                    #GREY-BUTTON-CLICK
DRY EXAMPLE: GLOBAL VOICES

• Elegantly organized IE hacks
 and Right-To-Left (RTL)
 styles into groups for the
 common fixes.

• Font-sizegroups re-used in
 optional Large-Font theme.
2 PRINCIPLES OF GOOD CSS

• Keep   style separate from content.

 • HTML  should be structural. Tags, classes and IDs should refer
  to the content itself rather than how it looks.

• Avoid   specificity by harnessing the cascade.

 • Selectors
           and definitions should be as global as possible for
  design consistency and to avoid specificity collisions.
DRY: DON’T REPEAT YOURSELF
• a.k.a   "Single Source of Truth" principle.

• "Everypiece of knowledge must have a single, unambiguous,
 authoritative representation within a system." *

• DRY code means all uses of data change simultaneously rather
 than needing to be replicated.

• DRY  is the fundamental reason to use of variables and
 functions in all programming.

• Bugs      love a wet mess.
                  * http://en.wikipedia.org/wiki/Don't_repeat_yourself
PROBLEMS WITH KEEPING CSS DRY

• No  variables - We can’t re-use values across properties (I.e
 a color hex).

• No  mixins (functions) - No way to re-use sets of property/
 value pairs across definitions.

• Result: Constant   duplication of style definitions across different
 selectors.
BRUTE FORCE: CSS PREPARSERS
•   Add a new language based on CSS that
    has the necessary tools and a new
    parsing layer to read it.

    •   Variables to re-use values across
                                                       Variables in LESS*
        definitions.

    •   Mixins to include a class inside
        another class.

    •   All kinds of other programmy things
        (functions, switch conditions)
                                                       Mixins in LESS*
* E.g. http://lesscss.org/ and http://sass-lang.com/
CSS PREPARSERS: ISSUES

• LESS   and SASS do create a fantastic, DRY-capable CSS.

• BUT  at the cost of destandardization and dependence on
 external libraries. It isn’t CSS.

• They
     can still be misused to create wet, sloppy stylesheets.
 Organizational methodology remains vital.

• Question: How    can we get the same effect with standard CSS?
PRINCIPLES OF DRY CSS
            (TL;DR)
• Don't  Repeat Yourself. Never repeat a style/property
 definition if you can avoid it.

• Group  selectors with shared properties rather than
 defining them separately.
CREATING DRY CSS

• Group selectors that share
 properties above the properties
 they share.

• Name   the groups based on their
 role in the design.

• Use the name as an ID at the top
 of the list and a class at bottom.
ORGANIZING DRY CSS
• Decide on group types and
 groups as necessary for your
 design, operational needs
 and/or other CSS
 methodologies.

• Recommended: Colors, Text,
 Shapes, Structures, Modules.

• At right: GV’s DRY groups,
 visualized by CSSEdit for
 Mac*
                  * http://macrabbit.com/espresso/
KEEPING IT DRY

• Make individual selectors as rare
 and sparse as possible, only use
 them as exceptions.

• Always   have an answer to "Why
 isn't this part of a group?"

• Don’t
      go crazy. Benefits scale even if
 some definitions remain moist.
BENEFITS OF DRY CSS

•2 simple rules to follow that ensure a solid organizational
 structure.

• Less   CSS, shorter and smaller (kb) stylesheets.

• Promotes    good design practice and uniform updates.

• Uses   only philosophically and syntactically standard CSS.
BENEFITS:
     PROMOTES CONCEPTUAL DESIGN
• Encourages  you to think in terms of style patterns (groups),
 rather than individual objects.

• Naming    of groups encourages rational organization of designs.

• Overalldesign tightens up, related objects become stylistically
 paired rather than simply matching.

• Listing
        all group members together encourages optimization
 and generalization of selectors because you see how
 interrelated/inheritable they are.
BENEFITS:
EDITS TO GROUPS AFFECT ALL MEMBERS

• Avoids   need to find all related styles to match changes.

• Changes   are less likely to be inconsistently applied.

• When   testing changes the dev sees all group members change
 as well.

• Moving   selectors between groups to restyle is fast and easy.
BENEFITS:
      TAKES ADVANTAGE OF INSPECTORS
•   Inspecting an object shows cascade of
    groups it participates in.

•   Group "name" (starting ID, i.e.
    #SMALL-TEXT) is visible in inspector.

•   Seeing all group members informs
    dev of related elements that should
    be considered.

•   Live-edits expose the change in
    related items as well.
BENEFITS:
DOESN’T REQUIRE CHANGES TO HTML

• Uses   whatever classes and IDs are already present.

• IfHTML needs editing it's only to add more detailed semantic
  classes to use in your DRY groups.

• Useful
       when generated HTML is out of your control
  (WordPress core/plugins, 3rd party widgets)
BENEFITS:
     COMPLETELY STANDARD
• Simply   an organizing princinple for normal CSS.

• Adheres    to separation of style and content.

• Bothbackward and forward compatible, from IE6 hacks to
 prefixed CSS3 properties.

• CSS    can be pasted anywhere and just work.

• Groupscan be extracted and re-used elsewhere by removing
 group members and inserting new ones.
BENEFITS:
         INTEGRATES WITH OTHER
            METHODOLOGIES
• Compatible with most other CSS methodologies like grids,
 OOCSS* or SMACSS** because the way you organize your
 groups is up to you.

• Progressiveenhancement and browser support is your
 choice. DRY only defines how you organize your selectors and
 properties.

   * https://github.com/stubbornella/oocss/wiki ** http://smacss.com/book/
PERFORMANCE ISSUES?
• TL;DR:      Probably not.

• "Formost web sites, the possible performance gains from
 optimizing CSS selectors will be small, and are not worth the
 costs." ~Steve Sounders*

• Having   many selectors does not inherently hurt performance.

• SeeSteve Sounders research** for optimizations that matter
 (and can be applied to DRY CSS).
  * http://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors/
        ** http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/
OOCSS: "OBJECT ORIENTED"
• “Separate   structure and           • Implementation
 skin.”
                                         • Define   re-usable classes
• “Separate   container and                like .media, .box and .red
 content.”
                                         • Add  them to HTML tags
• Objectsare re-usable                     throughout your site to
 content patterns.                         create a consistent and
                                           efficient design.
• Skins
      are sets of visual
 decorations to be applied to
 objects.                                                              Sources
                               https://github.com/stubbornella/oocss/wiki/FAQ
                         http://slideshare.net/stubbornella/object-oriented-css
DRY CSS <3 OOCSS
• The   fundamental principles and goals are the same:

 • Create   logical style groups that define your site.

 • Apply  them to elements rather than redefining css on many
   selectors.

 • Focus  on consistency of objects across the site through
   direct style linkage.

• “Object-orientation” can
                        be integrated into a DRY approach
 when choosing your groups and group types.
DRY CSS > OOCSS
• The    difference:

  • DRY     stacks selectors above a single definition in the CSS.

  • OOCSS  applies generic classes to HTML tags throughout
   the document.

• OOCSS    violates the separation of content and style by
 polluting HTML with meaningless style-classes.

     is unnecessary because DRY CSS can achieve the
• This
 same goal while maintaining separation.
DRY CSS > OOCSS (DETAILS)
• DRY offers an easy way to route around situations where
 OOCSS classes can't be added to HTML (out of your
 control, inconvenient, undesirable).

• Generic  group class (i.e .small-text) for each DRY group can
 still be used in OOCSS way if needed (especially in transient
 content rather than templates).

• DRY  allows group membership to be managed without
 editing HTML templates. Less files to edit, less people involved.

• DRY   keeps style and content separate LIKE IT SHOULD BE.
DRY CSS REVIEW
Group re-usable     Name the         Add selectors to
  properties      groups logically    various groups
QUESTIONS?
DRY CSS
A DON’T-REPEAT-YOURSELF METHODOLOGY
  FOR CREATING EFFICIENT, UNIFIED AND
         SCALABLE STYLESHEETS

Jeremy Clarke • http://jeremyclarke.org

                  Creative Commons Share Alike
                   http://creativecommons.org/licenses/by-sa/3.0/



                 Download these slides:
        http://slideshare.net/jeremyclarke
1 of 32

Recommended

CSS For Backend Developers by
CSS For Backend DevelopersCSS For Backend Developers
CSS For Backend Developers10Clouds
1.5K views60 slides
CSS Best practice by
CSS Best practiceCSS Best practice
CSS Best practiceRuss Weakley
7.2K views30 slides
OOCSS, SMACSS or BEM? by
OOCSS, SMACSS or BEM?OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?Michael Posso
7.8K views41 slides
Web components by
Web componentsWeb components
Web componentsGil Fink
517 views45 slides
World of CSS Grid by
World of CSS GridWorld of CSS Grid
World of CSS GridElad Shechter
958 views40 slides
CSS - OOCSS, SMACSS and more by
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreRuss Weakley
113.7K views169 slides

More Related Content

What's hot

Less vs sass by
Less vs sassLess vs sass
Less vs sassAya Edamoto
12.7K views16 slides
Introduction to sass by
Introduction to sassIntroduction to sass
Introduction to sassAnoop Raveendran
984 views22 slides
Css to-scss by
Css to-scssCss to-scss
Css to-scssfrontendne
1.1K views18 slides
Intro to css & sass by
Intro to css & sassIntro to css & sass
Intro to css & sassSean Wolfe
3K views212 slides
CSS media types by
CSS media typesCSS media types
CSS media typesRuss Weakley
894 views44 slides
CSS framework By Palash by
CSS framework By PalashCSS framework By Palash
CSS framework By PalashPalashBajpai
400 views21 slides

What's hot(20)

Less vs sass by Aya Edamoto
Less vs sassLess vs sass
Less vs sass
Aya Edamoto12.7K views
Css to-scss by frontendne
Css to-scssCss to-scss
Css to-scss
frontendne1.1K views
Intro to css & sass by Sean Wolfe
Intro to css & sassIntro to css & sass
Intro to css & sass
Sean Wolfe3K views
CSS framework By Palash by PalashBajpai
CSS framework By PalashCSS framework By Palash
CSS framework By Palash
PalashBajpai400 views
Tailwind CSS.11.pptx by Harish Verma
Tailwind CSS.11.pptxTailwind CSS.11.pptx
Tailwind CSS.11.pptx
Harish Verma1.7K views
[111015/아꿈사] HTML5를 여행하는 비(非) 웹 개발자를 위한 안내서 - 1부 웹소켓. by sung ki choi
[111015/아꿈사] HTML5를 여행하는 비(非) 웹 개발자를 위한 안내서 - 1부 웹소켓.[111015/아꿈사] HTML5를 여행하는 비(非) 웹 개발자를 위한 안내서 - 1부 웹소켓.
[111015/아꿈사] HTML5를 여행하는 비(非) 웹 개발자를 위한 안내서 - 1부 웹소켓.
sung ki choi8.1K views
Tailwind: The Future of CSS is Here! by Abdullah Al Mahi
Tailwind: The Future of CSS is Here!Tailwind: The Future of CSS is Here!
Tailwind: The Future of CSS is Here!
Abdullah Al Mahi197 views
Introduction to SASS by Jon Dean
Introduction to SASSIntroduction to SASS
Introduction to SASS
Jon Dean13K views
How Cascading Style Sheets (CSS) Works by Amit Tyagi
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi79.4K views
Css Basics by Jay Patel
Css BasicsCss Basics
Css Basics
Jay Patel1.1K views
Introducing CSS Grid Layout by Rachel Andrew
Introducing CSS Grid LayoutIntroducing CSS Grid Layout
Introducing CSS Grid Layout
Rachel Andrew4.8K views
An Introduction to CSS Frameworks by Adrian Westlake
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS Frameworks
Adrian Westlake2.6K views
CSS Dasar #6 : Background by Sandhika Galih
CSS Dasar #6 : BackgroundCSS Dasar #6 : Background
CSS Dasar #6 : Background
Sandhika Galih2.3K views

Viewers also liked

Put A Map On It! Enhanced geolocation in WordPress with Geo Mashup by
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 MashupJer Clarke
9.3K views30 slides
Object Oriented CSS by
Object Oriented CSSObject Oriented CSS
Object Oriented CSSNicole Sullivan
283.2K views64 slides
Atomic design by
Atomic designAtomic design
Atomic designBrad Frost
2M views173 slides
Методологии верстки by
Методологии версткиМетодологии верстки
Методологии версткиElizaveta Selivanova
25K views72 slides
Our Best Practices Are Killing Us by
Our Best Practices Are Killing UsOur Best Practices Are Killing Us
Our Best Practices Are Killing UsNicole Sullivan
175.5K views111 slides
Css Preprocessors by
Css PreprocessorsCss Preprocessors
Css PreprocessorsSaulo Oliveira
387 views17 slides

Viewers also liked(20)

Put A Map On It! Enhanced geolocation in WordPress with Geo Mashup by Jer Clarke
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
Jer Clarke9.3K views
Our Best Practices Are Killing Us by Nicole Sullivan
Our Best Practices Are Killing UsOur Best Practices Are Killing Us
Our Best Practices Are Killing Us
Nicole Sullivan175.5K views
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides by Jer Clarke
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slidesKeep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Jer Clarke5.2K views
CSS Methodology by Zohar Arad
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad964 views
BEM It! for Brandwatch by Max Shirshin
BEM It! for BrandwatchBEM It! for Brandwatch
BEM It! for Brandwatch
Max Shirshin18.1K views
Architecting single-page front-end apps by Zohar Arad
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
Zohar Arad39.6K views
Css3 and gwt in perfect harmony by Arcbees
Css3 and gwt in perfect harmonyCss3 and gwt in perfect harmony
Css3 and gwt in perfect harmony
Arcbees2.8K views
Responsive Design Workflow (Breaking Development Conference 2012 Orlando) by Stephen Hay
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
Stephen Hay42.2K views
The Why and What of Pattern Lab by Dave Olsen
The Why and What of Pattern LabThe Why and What of Pattern Lab
The Why and What of Pattern Lab
Dave Olsen14.3K views
Incorporating Video into your Link Building Strategy by Phil Nottingham
Incorporating Video into your Link Building StrategyIncorporating Video into your Link Building Strategy
Incorporating Video into your Link Building Strategy
Phil Nottingham170.9K views

Similar to DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified and Scalable stylesheets

WordCamp NYC - DRY CSS by
WordCamp NYC - DRY CSSWordCamp NYC - DRY CSS
WordCamp NYC - DRY CSSJer Clarke
3.9K views30 slides
What is-sass-by-lucas-castro by
What is-sass-by-lucas-castroWhat is-sass-by-lucas-castro
What is-sass-by-lucas-castroLucas Castro
526 views46 slides
Complete Lecture on Css presentation by
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
9.9K views61 slides
4. Web Technology CSS Basics-1 by
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1Jyoti Yadav
46 views64 slides
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme by
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeSuzanne Dergacheva
1K views82 slides
WEBD 162: Intro to CSS by
WEBD 162: Intro to CSSWEBD 162: Intro to CSS
WEBD 162: Intro to CSSpalomateach
573 views11 slides

Similar to DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified and Scalable stylesheets(20)

WordCamp NYC - DRY CSS by Jer Clarke
WordCamp NYC - DRY CSSWordCamp NYC - DRY CSS
WordCamp NYC - DRY CSS
Jer Clarke3.9K views
What is-sass-by-lucas-castro by Lucas Castro
What is-sass-by-lucas-castroWhat is-sass-by-lucas-castro
What is-sass-by-lucas-castro
Lucas Castro526 views
Complete Lecture on Css presentation by Salman Memon
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
Salman Memon9.9K views
4. Web Technology CSS Basics-1 by Jyoti Yadav
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
Jyoti Yadav46 views
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme by Suzanne Dergacheva
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
WEBD 162: Intro to CSS by palomateach
WEBD 162: Intro to CSSWEBD 162: Intro to CSS
WEBD 162: Intro to CSS
palomateach573 views
SASS - Syntactically Awesome Stylesheet by Neha Sharma
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome Stylesheet
Neha Sharma1.2K views
Web design-workflow by Peter Kaizer
Web design-workflowWeb design-workflow
Web design-workflow
Peter Kaizer1.6K views
Sane CSS - A modern approach to CSS by Lee Cheneler
Sane CSS - A modern approach to CSSSane CSS - A modern approach to CSS
Sane CSS - A modern approach to CSS
Lee Cheneler356 views
Object Oriented CSS for rapid, scalable and maintainable development by Graeme Blackwood
Object Oriented CSS for rapid, scalable and maintainable developmentObject Oriented CSS for rapid, scalable and maintainable development
Object Oriented CSS for rapid, scalable and maintainable development
Graeme Blackwood5.1K views
Css presentation lecture 1 by Mudasir Syed
Css presentation lecture 1Css presentation lecture 1
Css presentation lecture 1
Mudasir Syed529 views
Css presentation lecture 3 by Mudasir Syed
Css presentation lecture 3Css presentation lecture 3
Css presentation lecture 3
Mudasir Syed290 views
CSS for Design Systems by Adam Kudrna
CSS for Design SystemsCSS for Design Systems
CSS for Design Systems
Adam Kudrna144 views

More from Jer Clarke

globalvoices.org - How our CC license spawned a world class translation commu... by
globalvoices.org - How our CC license spawned a world class translation commu...globalvoices.org - How our CC license spawned a world class translation commu...
globalvoices.org - How our CC license spawned a world class translation commu...Jer Clarke
758 views22 slides
Global Voices proves Creative Commons is Awesome • CC Salon Montreal by
Global Voices proves Creative Commons is Awesome • CC Salon MontrealGlobal Voices proves Creative Commons is Awesome • CC Salon Montreal
Global Voices proves Creative Commons is Awesome • CC Salon MontrealJer Clarke
672 views20 slides
Widgetize Everything: Building smarter WordPress themes with Widgets and Temp... by
Widgetize Everything: Building smarter WordPress themes with Widgets and Temp...Widgetize Everything: Building smarter WordPress themes with Widgets and Temp...
Widgetize Everything: Building smarter WordPress themes with Widgets and Temp...Jer Clarke
2.9K views24 slides
NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009 by
NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009
NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009Jer Clarke
1.5K views18 slides
Caching and Optimization for WordPress by
Caching and Optimization for WordPressCaching and Optimization for WordPress
Caching and Optimization for WordPressJer Clarke
2.5K views31 slides
WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09 by
WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09
WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09Jer Clarke
485 views42 slides

More from Jer Clarke(8)

globalvoices.org - How our CC license spawned a world class translation commu... by Jer Clarke
globalvoices.org - How our CC license spawned a world class translation commu...globalvoices.org - How our CC license spawned a world class translation commu...
globalvoices.org - How our CC license spawned a world class translation commu...
Jer Clarke758 views
Global Voices proves Creative Commons is Awesome • CC Salon Montreal by Jer Clarke
Global Voices proves Creative Commons is Awesome • CC Salon MontrealGlobal Voices proves Creative Commons is Awesome • CC Salon Montreal
Global Voices proves Creative Commons is Awesome • CC Salon Montreal
Jer Clarke672 views
Widgetize Everything: Building smarter WordPress themes with Widgets and Temp... by Jer Clarke
Widgetize Everything: Building smarter WordPress themes with Widgets and Temp...Widgetize Everything: Building smarter WordPress themes with Widgets and Temp...
Widgetize Everything: Building smarter WordPress themes with Widgets and Temp...
Jer Clarke2.9K views
NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009 by Jer Clarke
NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009
NetBeans, IDEs and faster programming for WordPress - WordCamp NYC 2009
Jer Clarke1.5K views
Caching and Optimization for WordPress by Jer Clarke
Caching and Optimization for WordPressCaching and Optimization for WordPress
Caching and Optimization for WordPress
Jer Clarke2.5K views
WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09 by Jer Clarke
WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09
WordPress Code and Setup Strategies and Advice, WordCamp Toronto '09
Jer Clarke485 views
Global Voices Generic Presentation by Jer Clarke
Global Voices Generic PresentationGlobal Voices Generic Presentation
Global Voices Generic Presentation
Jer Clarke2.5K views
Global Voices - Democratising the web with Wordpress and Love by Jer Clarke
Global Voices - Democratising the web with Wordpress and LoveGlobal Voices - Democratising the web with Wordpress and Love
Global Voices - Democratising the web with Wordpress and Love
Jer Clarke7.4K views

Recently uploaded

CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
63 views15 slides
Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
76 views26 slides
Future of AR - Facebook Presentation by
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook PresentationRob McCarty
54 views27 slides
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPoolShapeBlue
56 views10 slides
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...ShapeBlue
69 views29 slides
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
149 views7 slides

Recently uploaded(20)

CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue63 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely76 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty54 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue56 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue69 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue149 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson142 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue74 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue110 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10110 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue218 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue48 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu287 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE67 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue121 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue138 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue97 views

DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified and Scalable stylesheets

  • 1. DRY CSS A DON’T-REPEAT-YOURSELF METHODOLOGY FOR CREATING EFFICIENT, UNIFIED AND SCALABLE STYLESHEETS Jeremy Clarke • http://jeremyclarke.org Download these slides: http://slideshare.net/jeremyclarke
  • 2. WHO IS JEREMY CLARKE? • Communications Studies at Concordia University. • HTML+CSS since 2003 • Montreal WordPress Community/ WordCamp organizer.
  • 3. OVERVIEW • An example of DRY CSS, Global Voices. • DRY principle and problems with CSS. • Preparsers (LESS and SASS) and their issues. • DRY CSS theory, implementation and benefits. • Appendix: OOCSS
  • 5. DRY EXAMPLE: GLOBAL VOICES Before DRY CSS After DRY CSS • Applying DRY reduced 4200 5,000 lines to 2400. 3,750 • Standardized Shapes, text sizes, colors and modules. 2,500 1,250 • Nothinglost, just better organized. 0 Lines of CSS
  • 6. DRY EXAMPLE: GLOBAL VOICES • Groups define shared properties. • Groups have many selectors. • Each property/value pair is defined only once.
  • 7. DRY EXAMPLE: GLOBAL VOICES #ROUNDED5-BORDER2 #MEDIUM-ORANGE-TEXT #PALE-GREY-BACKGROUND #GREY-BUTTON #GREY-BUTTON-HOVER #GREY-BUTTON-CLICK
  • 8. DRY EXAMPLE: GLOBAL VOICES • Elegantly organized IE hacks and Right-To-Left (RTL) styles into groups for the common fixes. • Font-sizegroups re-used in optional Large-Font theme.
  • 9. 2 PRINCIPLES OF GOOD CSS • Keep style separate from content. • HTML should be structural. Tags, classes and IDs should refer to the content itself rather than how it looks. • Avoid specificity by harnessing the cascade. • Selectors and definitions should be as global as possible for design consistency and to avoid specificity collisions.
  • 10. DRY: DON’T REPEAT YOURSELF • a.k.a "Single Source of Truth" principle. • "Everypiece of knowledge must have a single, unambiguous, authoritative representation within a system." * • DRY code means all uses of data change simultaneously rather than needing to be replicated. • DRY is the fundamental reason to use of variables and functions in all programming. • Bugs love a wet mess. * http://en.wikipedia.org/wiki/Don't_repeat_yourself
  • 11. PROBLEMS WITH KEEPING CSS DRY • No variables - We can’t re-use values across properties (I.e a color hex). • No mixins (functions) - No way to re-use sets of property/ value pairs across definitions. • Result: Constant duplication of style definitions across different selectors.
  • 12. BRUTE FORCE: CSS PREPARSERS • Add a new language based on CSS that has the necessary tools and a new parsing layer to read it. • Variables to re-use values across Variables in LESS* definitions. • Mixins to include a class inside another class. • All kinds of other programmy things (functions, switch conditions) Mixins in LESS* * E.g. http://lesscss.org/ and http://sass-lang.com/
  • 13. CSS PREPARSERS: ISSUES • LESS and SASS do create a fantastic, DRY-capable CSS. • BUT at the cost of destandardization and dependence on external libraries. It isn’t CSS. • They can still be misused to create wet, sloppy stylesheets. Organizational methodology remains vital. • Question: How can we get the same effect with standard CSS?
  • 14. PRINCIPLES OF DRY CSS (TL;DR) • Don't Repeat Yourself. Never repeat a style/property definition if you can avoid it. • Group selectors with shared properties rather than defining them separately.
  • 15. CREATING DRY CSS • Group selectors that share properties above the properties they share. • Name the groups based on their role in the design. • Use the name as an ID at the top of the list and a class at bottom.
  • 16. ORGANIZING DRY CSS • Decide on group types and groups as necessary for your design, operational needs and/or other CSS methodologies. • Recommended: Colors, Text, Shapes, Structures, Modules. • At right: GV’s DRY groups, visualized by CSSEdit for Mac* * http://macrabbit.com/espresso/
  • 17. KEEPING IT DRY • Make individual selectors as rare and sparse as possible, only use them as exceptions. • Always have an answer to "Why isn't this part of a group?" • Don’t go crazy. Benefits scale even if some definitions remain moist.
  • 18. BENEFITS OF DRY CSS •2 simple rules to follow that ensure a solid organizational structure. • Less CSS, shorter and smaller (kb) stylesheets. • Promotes good design practice and uniform updates. • Uses only philosophically and syntactically standard CSS.
  • 19. BENEFITS: PROMOTES CONCEPTUAL DESIGN • Encourages you to think in terms of style patterns (groups), rather than individual objects. • Naming of groups encourages rational organization of designs. • Overalldesign tightens up, related objects become stylistically paired rather than simply matching. • Listing all group members together encourages optimization and generalization of selectors because you see how interrelated/inheritable they are.
  • 20. BENEFITS: EDITS TO GROUPS AFFECT ALL MEMBERS • Avoids need to find all related styles to match changes. • Changes are less likely to be inconsistently applied. • When testing changes the dev sees all group members change as well. • Moving selectors between groups to restyle is fast and easy.
  • 21. BENEFITS: TAKES ADVANTAGE OF INSPECTORS • Inspecting an object shows cascade of groups it participates in. • Group "name" (starting ID, i.e. #SMALL-TEXT) is visible in inspector. • Seeing all group members informs dev of related elements that should be considered. • Live-edits expose the change in related items as well.
  • 22. BENEFITS: DOESN’T REQUIRE CHANGES TO HTML • Uses whatever classes and IDs are already present. • IfHTML needs editing it's only to add more detailed semantic classes to use in your DRY groups. • Useful when generated HTML is out of your control (WordPress core/plugins, 3rd party widgets)
  • 23. BENEFITS: COMPLETELY STANDARD • Simply an organizing princinple for normal CSS. • Adheres to separation of style and content. • Bothbackward and forward compatible, from IE6 hacks to prefixed CSS3 properties. • CSS can be pasted anywhere and just work. • Groupscan be extracted and re-used elsewhere by removing group members and inserting new ones.
  • 24. BENEFITS: INTEGRATES WITH OTHER METHODOLOGIES • Compatible with most other CSS methodologies like grids, OOCSS* or SMACSS** because the way you organize your groups is up to you. • Progressiveenhancement and browser support is your choice. DRY only defines how you organize your selectors and properties. * https://github.com/stubbornella/oocss/wiki ** http://smacss.com/book/
  • 25. PERFORMANCE ISSUES? • TL;DR: Probably not. • "Formost web sites, the possible performance gains from optimizing CSS selectors will be small, and are not worth the costs." ~Steve Sounders* • Having many selectors does not inherently hurt performance. • SeeSteve Sounders research** for optimizations that matter (and can be applied to DRY CSS). * http://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors/ ** http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/
  • 26. OOCSS: "OBJECT ORIENTED" • “Separate structure and • Implementation skin.” • Define re-usable classes • “Separate container and like .media, .box and .red content.” • Add them to HTML tags • Objectsare re-usable throughout your site to content patterns. create a consistent and efficient design. • Skins are sets of visual decorations to be applied to objects. Sources https://github.com/stubbornella/oocss/wiki/FAQ http://slideshare.net/stubbornella/object-oriented-css
  • 27. DRY CSS <3 OOCSS • The fundamental principles and goals are the same: • Create logical style groups that define your site. • Apply them to elements rather than redefining css on many selectors. • Focus on consistency of objects across the site through direct style linkage. • “Object-orientation” can be integrated into a DRY approach when choosing your groups and group types.
  • 28. DRY CSS > OOCSS • The difference: • DRY stacks selectors above a single definition in the CSS. • OOCSS applies generic classes to HTML tags throughout the document. • OOCSS violates the separation of content and style by polluting HTML with meaningless style-classes. is unnecessary because DRY CSS can achieve the • This same goal while maintaining separation.
  • 29. DRY CSS > OOCSS (DETAILS) • DRY offers an easy way to route around situations where OOCSS classes can't be added to HTML (out of your control, inconvenient, undesirable). • Generic group class (i.e .small-text) for each DRY group can still be used in OOCSS way if needed (especially in transient content rather than templates). • DRY allows group membership to be managed without editing HTML templates. Less files to edit, less people involved. • DRY keeps style and content separate LIKE IT SHOULD BE.
  • 30. DRY CSS REVIEW Group re-usable Name the Add selectors to properties groups logically various groups
  • 32. DRY CSS A DON’T-REPEAT-YOURSELF METHODOLOGY FOR CREATING EFFICIENT, UNIFIED AND SCALABLE STYLESHEETS Jeremy Clarke • http://jeremyclarke.org Creative Commons Share Alike http://creativecommons.org/licenses/by-sa/3.0/ Download these slides: http://slideshare.net/jeremyclarke