I don't know about you, but vanilla CSS always leaves me wanting more. It's a fairly simple language, can do some pretty powerful things, but after a while.. well, it can become rather tedious to work with. Enter Sass: Syntactically Awesome Stylesheets. Sass is a CSS meta-language and precompiler that makes the prettification of your website a breeze by adding invaluable features of more traditional programming languages. In this session, we'll jump right in to the Sass workflow and cover all the key game changers - nesting, variables, mixins, inheritance, and directives. We'll also cover some of the gotchyas, tools and extensions, and tips for organization and coding standards.
Prepared for self.conference at COBO Hall in Detroit, Michigan on May 30, 2014.
Updated for CodeMash January 2015.
Updated for Detroit Craftsman Guild March 2016.
12. What Is Sass?
1. An extension of CSS
SassScript Language. Fully CSS-compatible syntax.
13. What Is Sass?
1. An extension of CSS
SassScript Language. Fully CSS-compatible syntax.
2. A CSS preprocessor
SassScript MAGIC CSS
14. Where Did Sass Come From?
• 2007: Designed by
Hampton Catlin (Haml)
• Developed by Chris
Eppstein (Compass) and
Natalie Weizenbaum
15. Why Did They Make Sass?
Because vanilla CSS just
wasn’t cutting it any more.
16. Bert Bos, CSS Co-Inventor
CSS stops short of even more powerful
features […]. That is because these things
give power-users a lot of rope, but less
experienced users will unwittingly hang
themselves; or, more likely, be so scared
that they won’t even touch CSS.
“
17. What Does Sass Give
Us That CSS Doesn’t?
• Nesting
• Imports
• Variables
• Mixins
• Inheritance
• Functions
• Loops
• AWESOME
18. What Does Sass Give
Us That CSS Doesn’t?
• Reduced Repetition
• Cleaner Modularity
• Maintainability
• Scalability
• REAL PROGRAMMING!
29. Nesting Gotchya
Mirroring HTML nesting is
SUPER easy.
MAGIC?
Overly verbose and overly specific.
General Rule:
No more than 2-3 levels deep
Sass
CSS
30. Nesting The Parent Selector
You can reference parent selector(s) with an &
MAGIC
Sass CSS
31. Nesting The Parent Selector
The & can follow other selectors, too!
MAGIC
Sass
CSS
35. Imports
CSS @import has always
meant an extra file download.
Sass (application.scss)
Sass modifies @import to
instead include the resource
during compilation, rather
than on the client side.
46. Variable Uses
colors
font sizes
font families
font paths
padding
margins
breakpoints
border-radius
pseudo content
shadows
gradients
SELECTORS!
LOGIC!
ALL THE THINGS!!!1!
50. Math
• + addition
• - subtraction
• * multiplication
• / division
• % modulus
Sass gives us basic math operations.
Sass
SassyCSS
51. Math Functions
• abs($num) - absolute value
• ceil($num) - round up to closest whole number
• floor($num) - round down to closest whole number
• percentage($num) - convert to percentage
• round($num) - round to closest whole number
• max($list) - maximum list value
• min($list) - minimum list value
Sass comes with a set of math functions.
71. Resources
Sass-Lang.com
The Sass Way
Sass For Web Designers
Assembling Sass
SassNews Newsletter
SassConf
SassConf 2013 Videos
SassMeister
Sass Style Guide
#teamSass
72. Closing Tips
• Take it one step at a time.
• Keep an eye on your output.
• Don’t nest too deeply.
• Mind your @mixins and @media queries.
• Careful with your @extends.
• Modularize all the things.