• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Authoring Stylesheets with Compass & Sass
 

Authoring Stylesheets with Compass & Sass

on

  • 15,070 views

Slides from the talk I gave at the CSS Summit 2010.

Slides from the talk I gave at the CSS Summit 2010.

Statistics

Views

Total Views
15,070
Views on SlideShare
14,802
Embed Views
268

Actions

Likes
36
Downloads
358
Comments
1

7 Embeds 268

http://jinseok.posterous.com 232
http://www.schoox.com 15
http://www.hivelocity.co.jp 11
http://posterous.com 7
http://a0.twimg.com 1
http://www.techgig.com 1
http://www.dqbug.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • * graduated from Caltech in 2000 <br /> * 4 startups, F2E, UI Lead, UI Architect, etc <br /> * First Employee of Caring.com in 5/2007 <br /> * Discovered Sass about 2 years ago when it was already 2 years old, created sass port of blueprint css framework, created compass, joined the Sass core team, Recently joined the blueprint core team (again) <br />
  • <br />
  • <br />
  • CSS is a major front for the Browser War v2.0 <br /> Casualty of War: Front-End Developers <br /> What do all of these new features have in common? They&#x2019;re all about the browser -- None of them address how we author stylesheets. <br /> <br />
  • CSS is a major front for the Browser War v2.0 <br /> Casualty of War: Front-End Developers <br /> What do all of these new features have in common? They&#x2019;re all about the browser -- None of them address how we author stylesheets. <br /> <br />
  • <br />
  • * Sass is a stylesheet language - Built on the same primitives as CSS but with more expressiveness. <br /> * Compass is a framework that uses sass to help you author your stylesheets by providing shared tools, libraries, and standards that help users share stylesheets with each other. <br /> * Sass and Compass have Co-evolved over the past two years. Sass has existed for about 3.5 years. <br />
  • <br />
  • Example of Sass in action. <br /> &#x201C;I thought Sass was supposed to make my stylesheets smaller?&#x201D; <br /> Sass excels at making implicit relationships explicit -- smaller is not the goal: easier to maintain is the goal. Often this results in a smaller file. <br />
  • Global: $background-color, $foreground-color, $widget-width <br /> Scoped: $border-width <br />
  • <br />
  • <br />
  • <br />
  • * Later today, you&#x2019;ll hear from Nicole Sullivan, creator of OOCSS. <br /> * The idea of class inheritance came from her. <br /> * Nathan and I generalized it to selector inheritance and created the first complete implementation. <br /> * I think that Sass is a great compliment to the OOCSS framework. <br />
  • <br />
  • * Write colors how you think of them <br /> * operate on colors in the hsl domain <br /> * build themes from just a few base colors <br /> * keep color relationships explicit <br /> <br />
  • * Create mathematical expressions to simplify change. <br /> <br />
  • <br /> <br />
  • There are other control flow directives like @for, @while but these have only marginal usefulness. <br />
  • partials start with an underscore but the imports do not require the underscore. this facilitates converting to a partial. <br /> partials do not generate css files <br /> imports place the contents of the imported file at the point of import. imports make the mixins and global variables of the imports file available. <br />
  • <br />
  • Use .sass instead of .scss <br /> Completely interoperable <br /> less noise: curly braces => indentation, ; => newline <br /> @include => +, @mixin => = <br />
  • <br />
  • * resets <br /> * grids <br /> * typography <br />
  • Best practices and patterns that are proven to work across a range of browsers. <br />
  • None of these are frameworks. They are libraries. <br /> But it&#x2019;s easier to make a new term than convince everyone to start calling them &#x201C;css libraries&#x201D;. <br /> <br />
  • So Compass is a &#x201C;Stylesheet Authoring Framework&#x201D; <br /> <br /> Or for the geeks: A Meta Framework (A framework for css frameworks -- we&#x2019;ll get to this later) <br />
  • You might want to drag this to your dock <br /> <br /> Someday there will be a GUI. But until then, this really isn&#x2019;t very hard to do. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • * By putting the asset locations in a configuration file, you can let compass figure out how to tell the browser where they are. This makes it easier to refactor and still use relative urls when you want to. <br /> * At any time, you can set &#x201C;relative_assets = true&#x201D; and you&#x2019;ll be able to serve images off the local filesystem irrespective of your other settings. <br /> timestamps are automatically added to invalidate browser caches when images change. (can be disabled) <br />
  • * By putting the asset locations in a configuration file, you can let compass figure out how to tell the browser where they are. This makes it easier to refactor and still use relative urls when you want to. <br /> * At any time, you can set &#x201C;relative_assets = true&#x201D; and you&#x2019;ll be able to serve images off the local filesystem irrespective of your other settings. <br /> timestamps are automatically added to invalidate browser caches when images change. (can be disabled) <br />
  • This is the default, assets will be served root relative, via a web-server without specifying a host. <br />
  • Sometimes you find out your app will be hosted in a folder. <br />
  • a host may be specified by asset type. <br />
  • You can specify the asset host for each asset. <br /> <br />
  • Data urls let us embed assets directly in our stylesheets. <br /> Good for small images like icons where HTTP overhead is large compared to file size. <br /> Incurs encoding bloat: 33% uncompressed, 2-3% when gzipped, <br /> Doesn&#x2019;t work in IE6 & IE7 <br />
  • <br />
  • This is how the sausage is made. It&#x2019;s not pretty but the finished product tastes pretty good. Compass is your CSS sausage factory. <br /> <br /> But here&#x2019;s the thing... <br />
  • <br />
  • Ok, most of what&#x2019;s in compass is pretty straightforward. You could have written it yourself if you wanted. But not this. This was hard to do. There are dozens of man hours in this bit. <br />
  • Best practices, Battle tested, Updated regularly to reflect browser advancements. Your code remains the same. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Share libraries -- not just snippets on a blog post. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Authoring Stylesheets with Compass & Sass Authoring Stylesheets with Compass & Sass Presentation Transcript

  • AUTHORING STYLESHEETS PROJECT WITH SASS AND COMPASS DATE CLIENT 7/28/2010 CSS SUMMIT
  • You’re there for them. We’re here for you. CHRIS EPPSTEIN FOLLOW ME ON TWITTER: SOFTWARE ARCHITECT FOR CARING.COM @CHRISEPPSTEIN
  • HOLD ON TO YOUR HAT WE’VE GOT A LOT TO LEARN. CSS HAS GROWN UP.
  • Today Learn the Sass Syntax and features Learn your way around a compass project Overview of Compass Libraries Style a webpage in minutes Discover a new way of thinking about design
  • CSS3 33 New Selectors 120+ New Properties 3 New @-rules Enhanced Media Queries
  • CSS3 More Sophisticated More Powerful More Complex NO NEW FEATURES TO MANAGE COMPLEXITY.
  • Sass & Compass A workhorse for CSS developers. SIMPLIFYING CSS USING ABSTRACTIONS.
  • WHAT IS SASS? WHAT IS COMPASS?
  • Sass Features Variables Conditionals Nested Rules Server-side Imports Mixins Output Formatting & Compression Selector Inheritance Silent Comments Colors Optional Whitespace- Math Aware Syntax
  • Sass Syntax SASS CSS
  • Sass: Variables SASS CSS
  • Sass: Nested Rules SASS CSS
  • Sass: Mixins SASS CSS
  • Mixins: Write Your Own
  • Sass: Selector Inheritance SASS CSS
  • Sass: Colors SASS CSS
  • Sass: Colors Hex FUNCTIONS mix rgb/rgba darken/lighten hsl/hsla transparentize/opacify Named Colors compliment/adjust-hue Alpha Layers saturate/desaturate/ grayscale accessors & more HTTP://SASS-LANG.COM/DOCS/YARDOC/SASS/SCRIPT/FUNCTIONS.HTML
  • Sass: Mathematical Expressions SASS CSS
  • Sass: Numeric Units Handles any unit (even EXAMPLES those not yet defined in CSS) allows complex units in intermediate forms Understands compatible units
  • Sass: Conditionals
  • Sass: Server Side Imports _sidebar.scss screen.scss screen.css
  • Sass: Output Formats COMPACT COMPRESSED NESTED EXPANDED
  • Sass: Alternate Syntax
  • Sass: Alternate Syntax
  • QUESTIONS ABOUT SASS? LET’S CLEAR THOSE UP BEFORE WE GO ANY FURTHER DOWN THE RABBIT HOLE.
  • OOCSS CSS IS 14 YEARS OLD WE’VE DEVELOPED SOME BEST PRACTICES
  • OOCSS CSS FRAMEWORKS A CODIFICATION OF BEST PRACTICES
  • NOT FRAMEWORKS OOCSS COMPASS A REAL STYLESHEET FRAMEWORK
  • Features • Project Context • Core Library • Semantic Frameworks • Extensions • Community COMPASS A STYLESHEET AUTHORING FRAMEWORK
  • WINDOWS USERS: COMPASS WORKS FOR YOU TOO! DON’T BE SCARED WE’RE GOING TO USE THE TERMINAL
  • compass create <project> --using <framework> PROJECT CONTEXT CREATE A NEW PROJECT IN SECONDS
  • compass watch PROJECT CONTEXT COMPASS WILL WATCH FOR CHANGES AND COMPILE AUTOMATICALLY
  • compass help IF YOU NEED HELP SELF DOCUMENTING
  • IF YOU NEED HELP ONLINE DOCUMENTATION
  • http://groups.google.com/group/compass-users http://groups.google.com/group/haml IF YOU NEED HELP THE COMMUNITY
  • Projects are more than just Stylesheets Images Fonts JavaScripts
  • Where are your Assets? assets.scss
  • Relative Assets: config.rb No Web Server Required assets.scss assets.css
  • Absolute Assets: Web Server Required config.rb assets.scss assets.css
  • Set an Application config.rb Path Context assets.scss assets.css
  • Image Host (CDN/S3/etc) config.rb assets.scss assets.css
  • Use Asset Hosts config.rb assets.scss assets.css
  • In your CSS?! WIKIPEDIA REFERENCE COMPASS DOCUMENTATION
  • Asset Helpers stylesheet-url - url to assets stored in the CSS directory font-url - url to assets in the font directory image-url - url to assets in the images directory inline-image - embed an image inline-font-files - embed a font file http://compass-style.org/docs/reference/compass/helpers/urls/
  • CSS3 You’re going to hear a lot about CSS3 today. It’s pretty cool. But: It’s a #$%^@ mess. Vendor prefix hell Incompatible syntaxes Graceful degradation / progressive enhancement considerations Buggy implementations
  • Prefix Hell SIMPLE. LIKE IT WILL BE. ONLY NOW. REALLY? WHO DOES THIS? WHAT A PAIN.
  • Incompatible Implementations http://compass-style.org/docs/reference/compass/css3/gradient/
  • Compass CSS3 Modules UPDATED FOR YOU AS BROWSERS DEVELOP Background Clip Font Face Background Origin Gradient Background Size Inline Block Border Radius Opacity Box Text Shadow Box Shadow Transform Box Sizing Transition Columns http://compass-style.org/docs/reference/compass/css3/
  • Compass Utilities Resets Lists: pretty bullets, no-bullets, horizontal Sticky Footer lists, inline lists Clearfix Sprites Cross browser best Tables: striping practices: floats, mins borders & basic styling Links: hover-link, link- Text: ellipsis, no-wrap, colors, unstyled-link text-replacement http://compass-style.org/docs/reference/compass/utilities/
  • Mixin Library A La Carte Customizable
  • Browser Support All Modern Browsers Firefox 2 IE6 & 7 Exceptions are noted in the docs. Compass ♥’s progressive enhancement
  • The Zen of Sass ‣ Beautiful Markup ‣ Stylesheets that you can visualize ‣ Keep presentation in your stylesheets. ‣ Find your own code style ‣ Build your own framework ‣ Don’t use what you don’t like
  • Susy Created by an Eric Meyer for Compass Uses Natalie Down’s CSS Systems approach to grids. Can be elastic, fixed, or fluid. Vertical Rhythm Utilities http://susy.oddbird.net/
  • Some Great Extensions Lemonade - Sprite Generator 960.gs - The 960 grid system ported to Sass Lightboxes - Pure CSS lightboxes Slideshows - Pure CSS slideshows Fancy Buttons - Pure CSS Button Generator BUILDING AN EXTENSION IS EASY!
  • QUESTIONS ABOUT COMPASS?
  • My Teammates Nathan Wiezenbaum (@nex3) - Sass & Haml Eric Meyer (@eriiicam) - Compass, Susy Brandon Mathis (@imathis) - Compass, Fancy Buttons
  • Compass is Charityware If you use Compass & Sass and they make your life better, please help make someone else’s life better by making a tax-deductible donation to the United Mitochondrial Disease Foundation. http://umdf.org/compass
  • Photo Credits http://www.flickr.com/photos/oly_paul/3989018045/ http://www.flickr.com/photos/empics/2846078511/ http://www.flickr.com/photos/7202153@N03/3361299763/ http://www.flickr.com/photos/euart/282104427/
  • Similar Projects Less (Ruby, Javascript) CSScaffold (PHP) Turbine (PHP) xCSS (PHP) CleverCSS (Python) Mechanical CSS (PHP) HSS (Neko)