Think Vitamin CSS

  • 12,801 views
Uploaded on

These are slides from my talk at the Think Vitamin HTML & CSS online conference... …

These are slides from my talk at the Think Vitamin HTML & CSS online conference...

http://thinkvitamin.com/online-conferences/html-css/

More in: Design
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
12,801
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
424
Comments
0
Likes
54

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. THE WHY, HOW, AND WHEN? of CSS FRAMEWORKS http://thinkvitamin.com/online-conferences/
  • 2. Just a brief intro, then we’ll dig right into the good stuff... I’m Nathan. I am a designer (slash) front-end developer at Fellowship Technologies. http://fellowshiptech.com/
  • 3. You probably know me as the guy who made this... http://960.gs/
  • 4. But I’m not (entirely) one dimensional. Today, I we are going to discuss some of the benefits (and drawbacks) of using CSS frameworks such as...
  • 5. Blueprint, YUI 3, 960.gs, 1kb Grid
  • 6. “Any sufficiently advanced technology is indistinguishable from magic.” this scares me — Arthur C. Clarke http://en.wikipedia.org/wiki/Clarke's_three_laws
  • 7. You know why? CSS frameworks are not magic. Because CSS itself isn’t. Let’s not treat code like it’s mystical. (Same for jQuery. But that’s another soapbox entirely.)
  • 8. Veteran “ninjas” master a variety of tools – Not just one. FRAMEWORK BY H AND Use a framework as an extension of yourself – Not just as a crutch. http://imdb.com/title/tt1046173/
  • 9. WHY use a Framework? + Increase efficiency + Ease of maintenance + Code consistency + Repeatable process + Browser tested + CMS driven templates
  • 10. WHY not? – Learning curve – Code feels foreign – Bloated HTML – Longhand is quicker? – Bloated CSS – Unsemantic classes
  • 11. I have found that many of those who cry “bloat” (as a reason not to use frameworks) are themselves guilty of not doing all they can to reduce client-side latency. For instance, referencing multiple CSS files of the same media type is wasteful because it necessitates an HTTP request for each file, thereby delaying page rendering until all the files have been downloaded and parsed. Additionally, whitespace can quickly add up: newline characters, tabbed (or spaced) indentation, etc... — Nathan Smith (.Net Magazine July 2010)
  • 12. ... Regardless of if you are using a CSS framework, you can and should be using techniques to mitigate the impact of CSS downloads, including minification and concatenation – two fancy terms that simply refer to the removal of unnecessary whitespace, and combining multiple CSS files into one... If you want to minify your CSS manually, I would recommend CSS Drive’s compressor. — Nathan Smith (.Net Magazine July 2010) http://www.cssdrive.com/index.php/main/csscompressor/
  • 13. __________ “Unsemantic”
  • 14. DIV + SPAN ARE SEMANTICALLY MEANINGLESS (aka NEUTRAL) The div and span elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (span) or block-level (div) but impose no other presentational idioms on the content. — World Wide Web Consortium (W3C) http://www.w3.org/TR/html401/struct/global.html#h-7.5.4
  • 15. “Semantic Web” doesn’t involve CSS http://www.w3.org/DesignIssues/Semantic.html
  • 16. SORRY CSS... YOU WEREN’T INVITED TO THIS PARTY. WE STILL YOU. The term “Semantic Web” refers to W3C’s vision of the Web of linked data. Semantic Web technologies enable people to create data stores on the Web, build vocabularies, and write rules for handling data. Linked data are empowered by technologies such as RDF, SPARQL, OWL, and SKOS. — World Wide Web Consortium (W3C) http://www.w3.org/standards/semanticweb/
  • 17. DIV + ID / CLASS = ZERO SEMANTIC VALUE HTML5 TAGS = RICH SEMANTIC VALUE <div class="header"> <header> ... ... </div> </header> <div class="nav"> <nav> ... ... </div> </nav> <div class="article"> <article> ... ... </div> </article> <div class="footer"> <footer> ... ... </div> </footer>
  • 18. Semantics live here <tag class="peanut_butter jelly">Yummy content</tag> Not here
  • 19. If semantics keep you up at night... try SASS! http://sass-lang.com/
  • 20. Now that the ranting is done... HOW do I use a CSS framework?
  • 21. CSS Framework Comparison Matrix – Sounds really official, huh? Grid Typography PSD files Form styles Print styles “Plugins” RTL lang Blueprint ✓ ✓ ✓ ✓ ✓ ✓ ✓ YUI ✓ ✓ ✓ ✓ ✓ ✓ 960.gs ✓ ✓ ✓* ✓ 1KB Grid ✓
  • 22. * The 960 Grid System has templates for... + Acorn + Corel DRAW + Adobe Fireworks + Expression Design + Adobe Flash + GIMP + Adobe InDesign + InkScape + Adobe Illustrator + OmniGraffle + Adobe Photoshop + Visio ... and printable PDF sketch sheets. http://960.gs/
  • 23. Example of Blueprint HTML <div class="container"> <div class="span-8"> 1/3 width </div> <div class="span-8"> 1/3 width </div> <div class="span-8 last"> 1/3 width </div> <div class="span-12"> <div class="span-6"> 1/8 width </div> <div class="span-6 last"> 1/4 width </div> </div> <div class="span-12 last"> <div class="span-6 prepend-3 append-3 last"> 1/4 width </div> </div> </div> http://blueprintcss.org/
  • 24. Comparable example of 960.gs HTML (24-col) <div class="container_24"> <div class="grid_8"> 1/3 width </div> <div class="grid_8"> 1/3 width </div> <div class="grid_8"> 1/3 width </div> <div class="grid_12"> <div class="grid_6 alpha"> 1/8 width </div> <div class="grid_6 omega"> 1/4 width </div> </div> <div class="grid_12"> <div class="grid_6 prefix_3 suffix_3 alpha omega"> 1/4 width </div> </div> </div> http://960.gs/
  • 25. Example of Blueprint CSS .span-1, .pull-1, .span-2, .pull-2, ... { ... { float: left; float: left; margin-right: 10px; position:relative; } } .span-1 { .pull-1 { width: 30px; margin-left: -40px; } } .prepend-1 { .push-1, padding-left: 40px; .push-2, } ... { float: right; .append-1 { position:relative; padding-right: 40px; } } .push-1 { .last { margin: 0 -40px 1.5em 40px; margin-right: 0; } } http://blueprintcss.org/
  • 26. Example of 960.gs CSS (24-col) .container_24 .grid_1, .push_1, .container_24 .grid_2, .pull_1, ... { .push_2, display: inline; .pull_2 { float: left; position: relative; margin-left: 5px; } margin-right: 5px; } .container_24 .push_1 { left: 40px; .container_24 .grid_1 { } width: 30px; } .container_24 .pull_1 { right: 40px; .container_24 .prefix_1 { } padding-left: 40px; } .container_24 .suffix_1 { padding-right: 40px; Note: Whereas Blueprint’s push + pull } classes are used for content (offset .alpha { margin-left: 0; images / quotes), the push + pull classes } in 960.gs are used to rearrange entire .omega { } margin-right: 0; columns, independent of source order. This has practical implications for SEO. http://960.gs/
  • 27. BLUEPRINT GRID DIMENSIONS
  • 28. 960 (24-COL) GRID DIMENSIONS – What’s the difference? Glad you asked...
  • 29. Blueprint’s text can touch left / right edge of browser. Troublesome on mobile.
  • 30. 960.gs has a 5px (24-col) or 10px (12, 16-col) buffer on left / right side.
  • 31. YUI 3’s grid is fluid. It doesn’t use any floats. WHAT!? <div class="container"> <div class="yui3-g"> <div class="yui3-u-1-2"> 1/2 width </div> <div class="yui3-u-1-2"> 1/2 width </div> </div> <div class="yui3-g"> <div class="yui3-u-1-24"> 1/24 width </div> <div class="yui3-u-23-24"> 23/24 width </div> </div> </div> http://developer.yahoo.com/yui/3/
  • 32. .yui3-g { /* webkit: collapse white-space between units */ Example of YUI 3 Grid CSS letter-spacing: -0.31em; /* reset IE < 8 */ *letter-spacing: normal; /* IE < 8 && gecko: collapse white-space between units */ word-spacing: -0.43em; } Note: Because nothing is floated in YUI, this means that no additional files are .yui3-u, .yui3-u-1, needed in order to support languages that .yui3-u-1-2, ... { display: inline-block; read right-to-left (Hebrew, Arabic, etc). /* IE < 8: fake inline-block */ zoom: 1; *display: inline; letter-spacing: normal; word-spacing: normal; But because everything is essentially } vertical-align: top; display: inline-block, and is fluid width, .yui3-u-1 { this also means columns cannot be display: block; } rearranged for SEO purposes. Additionally, .yui3-u-1-2 { an extra wrapping <div> is required to width: 50%; } create gutters between content areas. .yui3-u-1-3 { width: 33.33333%; } http://developer.yahoo.com/yui/3/
  • 33. BROWSER ROUNDING % INCONSISTENCIES http://host.sonspring.com/yui3_grid/
  • 34. http://1kbgrid.com/
  • 35. 1KB Grid – Entire CSS file! .grid_1 { width:60px; } .grid_2 { width:140px; } .grid_3 { width:220px; } .grid_4 { width:300px; } .grid_5 { width:380px; } .grid_6 { width:460px; } .grid_7 .grid_8 { { width:540px; width:620px; } } The 1KB Grid has everything you .grid_9 .grid_10 { { width:700px; width:780px; } } need, and nothing you don’t. .grid_11 { width:860px; } .grid_12 { width:940px; } .column { Okay, maybe it doesn’t have everything margin: 0 10px; overflow: hidden; you need. It is – after all – less than 1 float: left; display: inline; kilobyte of code, so it can’t do it all. } .row { width: 960px; margin: 0 auto; No right-to-left support. No SEO column } overflow: hidden; re-ordering. But it is incredibly efficient! .row .row { margin: 0 -10px; width: auto; The 960 Grid System is 5.5KB. You can } display: inline-block; think of the 1KB Grid as a “lite” version. http://1kbgrid.com/
  • 36. Example of 1KB Grid HTML <div class="row"> <div class="column grid_6"> <div class="row"> <div class="column grid_6"> 1/2 width </div> </div> <div class="row"> <div class="column grid_2"> 1/6 width </div> <div class="column grid_2"> 1/6 width </div> <div class="column grid_2"> 1/6 width </div> </div> </div> <div class="column grid_6"> 1/2 width </div> </div> http://1kbgrid.com/
  • 37. So which CSS framework is the best? It depends... + What size site are you building? + Are you working alone or with a team? + Is pixel precision a make-or-break factor? + Do you need right-to-left language support? + Is your layout complex enough to merit SEO? + Do you want ready-made design or just a grid?
  • 38. YUI 3.0 Grid Pros: Cons: + Fluid (or fixed) Width – Source dependent layout + Easy RTL support – No gutters by default + Tested by Yahoo! devs – Rounding % inconstancies + Part of a larger ecosystem Use when: You need a flexible layout, and when a margin of error ± a few pixels is acceptable. http://developer.yahoo.com/yui/3/
  • 39. Blueprint Pros: Cons: + Ruby build scripts – Source dependent layout + Form, button, tab “plugins” – No outer gutters by default + Extensive typography – Design presuppositions + Print stylesheet (could be a positive though) Use when: You want a design that is ready to go “out of the box” with many of the default details handled for you by default. You want to generate grids via Ruby scripts. http://blueprintcss.org/
  • 40. 960.gs Pros: Cons: + 12, 16, or 24 column grids – Less features than YUI / BP + PS + FW plugins, templates – Focuses solely on grids + Possible SEO benefits (could be a positive though) + IA, Designer, Dev friendly Use when: Building a site with layouts driven by a CMS. If you are doing rapid prototyping or have IA > Designer > Dev workflow. Want layout to differ from source order. http://960.gs/
  • 41. 1KB Grid Pros: Cons: + Handy grid generator tool – Source dependent layout + Easy to get started – Features < than YUI / BP / 960 + Lightweight code – Focuses solely on grids + No extra nesting classes (could be a positive though) Use when: You are building a site that needs a grid layout, but the site’s requirements do not necessitate the overhead of a robust CSS framework. Or code size is a concern. http://1kbgrid.com/
  • 42. So, others’ frameworks are fine, but... WHEN should I roll my own framework?
  • 43. When to build your own... ✓ You have a specific need no other framework addresses ✓ You require a grid that is atypical of common frameworks ✓ To try your hand at architecting something others may use Pros: Cons: + 100% control over code – Debugging is all your burden + Build only what you need – Re-inventing the wheel?
  • 44. Some Helpful Resources...
  • 45. 5 Simple Steps to Designing Grid Systems A five-part series by Mark Boulton. http://www.markboulton.co.uk/journal/comments/five-simple-steps-to-designing-grid-systems-part-1
  • 46. Mark Boulton’s publishing company – Five Simple Steps http://fivesimplesteps.com/
  • 47. “Grid computing... and Design” – by Khoi Vinh http://www.subtraction.com/2004/12/31/grid-computi
  • 48. http://www.cameronmoll.com/archives/2006/12/gridding_the_960/
  • 49. http://www.cameronmoll.com/archives/2006/12/gridding_the_960/
  • 50. http://keynotekungfu.com/
  • 51. FURTHER READING... Frameworks for Designers – Jeff Croft — http://alistapart.com/articles/frameworksfordesigners Smart CSS ain’t always sexy CSS – Martin Ringlein — http://digital-web.com/articles/smart_CSS_aint_always_sexy_CSS/ Object Oriented CSS – Nicole Sullivan — http://wiki.github.com/stubbornella/oocss/
  • 52. Questions? — http://sonspring.com/contact — http://twitter.com/nathansmith Get the slides... — http://slideshare.net/nathansmith/think-vitamin-css