Presentation is loading. Please wait.

Presentation is loading. Please wait.

SCALING CSS (FOR LARGE WEB SITES) Tips, best practices and recommended methodologies for organizing and managing CSS for large web sites.

Similar presentations


Presentation on theme: "SCALING CSS (FOR LARGE WEB SITES) Tips, best practices and recommended methodologies for organizing and managing CSS for large web sites."— Presentation transcript:

1 SCALING CSS (FOR LARGE WEB SITES) Tips, best practices and recommended methodologies for organizing and managing CSS for large web sites.

2 PART I. KEYS TO MANAGING CSS General tips for managing and organizing your code

3 “Font sizes, like colour palettes, should be limited, preset and non- arbitrary.” — Harry Roberts http://csswizardry.com/2012/02/pragmatic-practical-font-sizing-in-css/ http://csswizardry.com/2012/02/pragmatic-practical-font-sizing-in-css/

4 Standardize your visual designs Design modular reusable components vs. pages. Clearly define what elements are and usage. If two designs are very similar, pick one. 2 slightly different shades of gray => Pick one. 2 font sizes with one pixel difference => Pick one.

5 “Whether it is a house or a web site, the latest techniques and trends require a solid understanding of fundamentals.” — Emily Lewis https://the-pastry-box-project.net/emily-lewis/2012-january-27 https://the-pastry-box-project.net/emily-lewis/2012-january-27

6 Use “POSH” (Plain Old Semantic HTML) Use appropriate simple semantic HTML tags. Examples: Map typography to tags: Headers = h1 – h6 Body text = p, etc. “Legalese” = small Form: fieldset, legend, label, input, textarea, select Table (data only): caption, thead, tbody, th, td HTML5: header, footer, nav, aside, etc. About Us Welcome Contact Location Map Welcome Subheading This is some info about us. copyright 2014

7 POSH: What is “semantic” HTML? Semantic tags include meaning about the type of content. Examples: p, h1 – h6, ul, ol, header, nav, etc. Non-semantic tags include little to no meaning. Examples: div, span Benefits of semantic tags: Improves accessibility and (potentially) SEO. Also makes html code easier to scan and comprehend and has benefits for styling.

8 POSH: choosing semantic html5 tags How to choose: http://html5doctor.c om/downloads/h5d -sectioning- flowchart.png http://html5doctor.c om/downloads/h5d -sectioning- flowchart.png

9 The Secret of Maintainability Keep it simple. — Jens O. Meiert http://meiert.com/ http://meiert.com/

10 Eliminate unnecessary CSS styles Make use of browser default styles and css inheritance. strong and h1 – h6 tags are bold by default (If you must define these in your css, your reset is too aggressive.) Most elements inherit font styles set on “body”. (Except a few form elements) Inline elements such as “a” use the line-height of parent. Don’t add styles you will have to override everywhere. Example: body {line-height: 1;} (Most text needs leading for legibility so may not be a good idea.)

11 Eliminate unnecessary CSS… Don’t make design pixel-perfect to PSD mock. PSD margins can be off. (Use standardized defaults.) Fonts render differently in Photoshop than in browser. Browser default line-height is often good enough. (Only specify in CSS if it’s a vital part of the design.) (CSS Dev Conf: “Design the Code, Not Pixel-Perfect Comps” Talk Summary: http://bit.ly/1tiSr5Yhttp://bit.ly/1tiSr5Y Slides: https://speakerdeck.com/katiekovalcin/design-the-code )https://speakerdeck.com/katiekovalcin/design-the-code

12 Eliminate unnecessary CSS… Search for instances of CSS repetition and delete. h1 small, h2 small, h3 small, h4 small, h5 small, h6 small { color: #6f6f6f; font-size: 60%; // already defined line-height: 0; // uses parent’s } small { font-size: 60%; line-height: inherit; // default } /* Change to => */ h1 small, h2 small, h3 small, h4 small, h5 small, h6 small { color: #6f6f6f; } small {font-size: 60%;}

13 Eliminate unnecessary CSS… Simple way to find repetitious styles: In Chrome: Use Developer Tools to inspect elements and see all applied styles. In Firefox: Install Firebug plugin to inspect elements. (Firebug also lets you edit html code and see the updates on the fly.)

14 “Write your sass/less so that the output is exactly how you would have written your CSS without it.” — Chris Coyler http://css-tricks.com/musings-on-preprocessing/ http://css-tricks.com/musings-on-preprocessing/

15 Make effective use of Sass Optimize for output CSS. Don’t over-nest selectors. “The Inception Rule” – Don’t go more than 4 levels deep (Limiting nesting also helps make css modular & reusable) http://thesassway.com/beginner/the- inception-rule http://thesassway.com/beginner/the- inception-rule // BAD: body {.page-wrapper {.page-header { nav { ul { li { a {color: #000;} } // MUCH BETTER:.page-wrapper {...}.page-header {...} // can add a new class name for nav:.page-nav { ul {...} li {...} a {...} }

16 Effective Sass: optimize output CSS Use @extend & placeholder to share styles. Don’t overuse mixins. (duplicates output CSS) // Sass Placeholder: %notice {...}.general-notice { @extend %notice; background: gray; }.success-notice { @extend %notice; background: green; }.error-notice { @extend %notice; background: red; } // Output CSS:.general-notice,.success-notice,.error-notice {...}.general-notice {background: gray;}.success-notice {background: green;}.error-notice {background: red;}

17 Make effective use of Sass Use Sass partials to separate and organize CSS. http://thesassway.com/beginner/how-to-structure-a-sass-project http://thesassway.com/beginner/how-to-structure-a-sass-project Separate styles into partials then include into one output css file. Reduce http requests which slow rendering of pages. Helps in modularity and locating specific styles. Share CSS files to build template or page specific style sheets. (Include shared standardized styles plus separate more specific styles)

18 PART II. TOOLS & METHODOLOGIES Methodologies to help manage designs and css code

19 Atomic Design http://bradfrostweb.com/blog/post/atomic-web-design/ http://bradfrostweb.com/blog/post/atomic-web-design/ Conceptual methodology for creating modular design systems. (Promotes consistency and scalability) Break design into 5 levels: 1. Atoms 2. Molecules 3. Organisms 4. Templates 5. Pages

20 Atomic Design: 1) Atoms Fundamental building blocks: Abstract: design aesthetic (“Super flat”, “Subtle skeuomorphism”) color palettes fonts Concrete elements: (individual HTML tags) form label input button h1 – h6, etc.

21 Atomic Design: 2) Molecules Molecules = Atoms combined into smallest fundamental units Example: Combine a form label, input and button to create a compact form such as a search form.

22 Atomic Design: 3) Organisms Groups of molecules joined to make more complex interface sections. Examples: A “masthead” consisting of logo, navigation and search form “product grid” repeating a “product item” in a list

23 Atomic Design: 4) Templates Groups organisms together in a layout. (underlying wireframe layouts for different page types) Example Types: signup funnel pages main content pages product detail pages company blog pages

24 Atomic Design: 5) Page Individual pages combining a template with actual content.

25 SMACSS (Scalable and Modular Architecture for CSS) https://smacss.com A system for categorizing and breaking up CSS rules to aid in building reusable patterns. (works well with Atomic Design principles) Main Categories: 1. Base: defaults (base styles for html tags) - atoms 2. Module: reusable modular components – molecules & organisms 3. Layout: page structure: grids, columns - template

26 SMACSS: organize CSS files Use SMACSS together with Sass to organize file structure.

27 OOCSS (“Object-Oriented” CSS) www.stubbornella.org “…repeating visual pattern, that can be abstracted into an independent snippet of HTML, CSS… object can then be reused throughout a site.” Media Object (classic example) Image to left, text to right. FB cut average CSS bytes per page by 19% with OOCSS http://www.slideshare.net/stubbornella/5-mistakes-of-massive-css http://www.stubbornella.org/content/2010/06/21/css-granularity-architecture/ http://www.slideshare.net/stubbornella/5-mistakes-of-massive-css http://www.stubbornella.org/content/2010/06/21/css-granularity-architecture/

28 OOCSS: Potential Drawbacks Encourages many css classes per html element Overuse of non-semantic classes Example: multiple classes used to add padding, margin, border, layout, “skin”, etc. Changing visual styles requires editing lots of HTML

29 OOCSS: The Solution = OOCSS + Sass “Besides the unmaintainable HTML, everything else about OOCSS is spot on. Abstracting repetition into modules is the only way to keep CSS maintainable on large projects. So how do we get the benefits without the drawbacks?” http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/ http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/ Use Sass together with OOCSS principles = “modular CSS without bloated, hard-to-maintain HTML” Use Sass @extend and placeholder to share styles without adding as separate classes in HTML..post {@extend %media-object; @extend %fancy-border …}.comment {@extend %media-object; @extend %lt-blue-bg …}

30 In Summary Key Points: 1. Define and reuse patterns in both designs and code. (Avoid “one-offs”.) 2. Understand and use features of coding languages: HTML, CSS, Sass A final important fact: Internet Explorer 6 – 9* have a CSS selector limit of 4,095. (Selector styles after the limit are ignored.) *Limit raised to 65,534 in IE10


Download ppt "SCALING CSS (FOR LARGE WEB SITES) Tips, best practices and recommended methodologies for organizing and managing CSS for large web sites."

Similar presentations


Ads by Google