SlideShare a Scribd company logo
Sass
(Syntactically Awesome Style Sheets)
What is it good for…
What is Sass?
“Sass is a meta-language on top of CSS that's used to describe
the style of a document cleanly and structurally, with more
power than flat CSS allows. Sass both provides a simpler, more
elegant syntax for CSS and implements various features that are
useful for creating manageable style sheets.”
- from http://sass-lang.com/
“Sass is an extension of CSS3, adding nested rules, Variables,
mixins, selector inheritance, and more. It’s translated to well-
formatted, standard CSS using the command line tool or a web-
framework plugin.”
- from internet
a little history…..
• Sass was first given life by Hampton Catlin in 2006, later
supported by Natalie weizembaum and chris eppstein
• Sass started life in ruby community
• Sass supports two syntaxes
– Indentation syntax with file ext .sass
– Css compatible syntax with file ext .SCSS
• Sass is free to use, require no license.
Why use it?
• Modularize (@import)
• Variables for maintainability
• Mixins improves reusability
• Reduces redundant rules (keep it DRY)
• Scalable and Maintainable
Make writing style more fun….
How do I install sass on my computer…
• On Mac
just run “gem install sass”
• On Window
download and install ruby (http://rubyinstaller.org/)
on cmd prompt - run
“gem install sass”
Data Types support by sass
• SassScript supports Seven data types
// number
example 10, 40, 50px, 60%
//string
example “foo”, “bar”, baz
//colors
example blue, #04a3f9, rgba(255,
0, 0, 0, 5)
//booleans
example true or false
//Null
example null
//list
example
$awesome-list: “.bar” “.foo”
“.odd”
//maps or hash
example
$alist: (error: red, warn: blue,
done: green)
Lets learn to read sass
• Variables
// sass syntax defining the variables
$red: #ff0b13
$blue-color: #091fff
p
color: $red
//scss syntax defining the variables
$red: #ff0b13;
$blue-color: #091fff;
p {
color: $red; }
Lets learn to read sass
•Nesting Rules
//sass syntax coloring the p
tag inside #id “awesome”
$common-color: red
div#awesome
p
color: $common-color
a
color: blue
&:hover
color: yellow
//scss syntax defining the
variables
$common-color: red;
div#awesome {
p {
color: $common-color;
a {
color: blue;
&:hover{
color: yellow;
}
}
}
}
Lets learn to read sass
Module structure with @import
//sass syntax
// main.sass
@import navigation
@import morestyle
body
max-width: 1200px
margin: auto
// “_morestyle.sass”
div
margin: auto
padding-top: 5px
//scss syntax
// main.scss
@import “navigation”
@import “morestyle”
*{
box-sizing: border-box;
}
body {
max-width: 1200px;
margin: auto;
}
// “_morestyle.scss”
div{
margin: auto;
padding-top: 5px;
}
Lets learn to read sass
•chaining selectors
//sass syntax
$link-color: blue
.content
color: yellow
&.main-container
a
color: $link-color
.main-container,
.mobile-container
width: 100%
//scss syntax
$link-color: blue;
.content {
color: yellow;
&.main-container {
a {
color: $link-
color;}
}
}
.main-container,.mobile-
container{ width: 100 }
Lets learn to read sass
@extend directive to extend existing rules
•//sass syntax
$box-color: yellow
.box
width: 100px
height: 200px
background-color: $box-color
.container
@extend .box
//scss syntax
$box-color: yellow
.box {
width: 100px;
height: 200px;
}
.container {
@extend .box
}
Lets learn to read sass
@extend directive with placeholder
•//sass syntax
$box-color: yellow
%box
width: 100px
height: 200px
background-color: $box-color
.container
@extend %box
//scss syntax
$box-color: yellow
%box {
width: 100px;
height: 200px;
}
.container {
@extend %box
}
Lets learn to read sass
@mixins
•//sass syntax
@import compass
=bs($width,$height: $width)
width: $width
height: $height
.square
+bs(100px)
+clearfix //compass mixin
//scss syntax
@import “compass”;
@mixin bs($width,$height:
$width) {
width: $width
height: $height
}
.square{
@include bs(100px)
@include clearfix //compass
mixin
}
Lets learn to read sass
@function directive
•//sass syntax
@import compass
$color: green
// function shuld return
@function double($value)
@return $value*2
.square
width:double(100px)
background-color:
shade($color,60%)
//scss syntax
@import “compass”;
$color: green;
// function shuld return
@function double($value)
@return $value*2
.square {
width:double(100px)
background-color:
shade($color,60%);
}
Lets learn to read sass
Programmatic Logic (Math calculations with Sass)
•//sass syntax
.addition
width: 20% + 50%
.sub
height: 20px - 10px
.division
top: (500/2)
.mul
width: 200px * 2
//scss syntax
.addition {
width: 20% + 50%; }
.sub {
height: 20px - 10px; }
.division {
top: (500/2); }
.mul {
width: 200px * 2; }
Lets learn to read sass
Programmatic Logic (control directive in sass)
•//sass syntax
$color-theme: orange
$color-brand: $color-theme
@if $color-theme == pink
$color-brand: pink
@else if $color-theme ==
orange
$color-brand: #ff9900
.brand
background-color: $color-
brand
//scss syntax
$color-theme: orange;
@if $color-theme == pink {
$color-brand: pink;
} @else if $color-theme ==
orange
{
$color-brand: #ff9900;
}
.brand { background-color:
$color-brand }
Lets learn to read sass
Programmatic Logic (control directives in sass)
•//sass syntax
$color-theme: orange
$color-brand: $color-theme
@if $color-theme == pink
$color-brand: pink
@else if $color-theme ==
orange
$color-brand: #ff9900
.brand
background-color: $color-
brand
//scss syntax
$color-theme: orange;
@if $color-theme == pink {
$color-brand: pink;
} @else if $color-theme ==
orange
{
$color-brand: #ff9900;
}
.brand { background-color:
$color-brand }
Lets learn to read sass
Programmatic Logic (@for loop in sass)
•//sass syntax
@for $i from 1 through 5
.div_#{$i}
color: red
@for $i from 6 through 10
.div_#{$i}
color: green
//scss syntax
@for $i from 1 through 5 {
.div_#{$i} {
color: red;
}
}
@for $i from 6 through 10 {
.div_#{$i} {
color: green;
}
}
Lets learn to read sass
Programmatic Logic (@each loop in sass)
•//sass syntax
$alist: ".odd" ".even"
@each $item in $alist
@if $item == '.odd'
#{$item}
color: green
@else
#{$item}
color: red
//scss syntax
$alist: ".odd" ".even" ;
@each $item in $alist {
@if $item == '.odd' {
#{$item} {
color: green; }
} @else {
#{$item} {
color: red; }
}
}
Lets learn to read sass
Programmatic Logic (@debug directive)
•//sass syntax
@function result($val)
@debug $val
@return $val * 2
.div
width: result(10px)
//scss syntax
@function result($val) {
@debug $val;
@return $val * 2;
}
.div {
width: result(10px);
}
how do you write sass
1. pick up a text editor (like atom or sublime… or
anything you like)
2. choose syntax style you want to follow (sass or
scss)
3. code your style rules and save the file as (.sass
or .scss) like so.
4 .then comes the compilation…..
how to compile sass
• on cmd prompt type “sass <filename>.sass” the
output will create new css file with
“<filename>.css” (please follow step above to
install sass on your mac or pc)
alternatively
• on cmd prompt type “compass <filename>.scss”
the output will create new css file with
“<filename>.css”
how to compile sass
• as a option you can use “compass watch” to
continuously watch for file changes and compile
them into css
So what next….
awesome you have learn about sass… next steps
• learn more complex topics (using compass)
• pick up a random css file re-code it into sass
• read awesome blogs from frontend
developers who works on sass and
coffeescript
• take same online course (if you can afford it)
– www.codeschool.com
– www.teamtreehouse.com (i like this
better)
Thank you
Lets go out there and write some sass…

More Related Content

PDF
Finding your way with Sass+Compass
PDF
CSS 開發加速指南-Sass & Compass
PDF
Theming and Sass
ODP
Deep dive into sass
PDF
Preprocessor presentation
PPT
CSS Preprocessors: LESS is more or look SASS-y trying
PPTX
Write LESS. DO more.
KEY
Advanced Technology for Web Application Design
Finding your way with Sass+Compass
CSS 開發加速指南-Sass & Compass
Theming and Sass
Deep dive into sass
Preprocessor presentation
CSS Preprocessors: LESS is more or look SASS-y trying
Write LESS. DO more.
Advanced Technology for Web Application Design

What's hot (20)

ODP
HTML5, CSS, JavaScript Style guide and coding conventions
PPTX
SASS is more than LESS
PDF
Compass, Sass, and the Enlightened CSS Developer
KEY
Wrangling the CSS Beast with Sass
PPTX
Elegant CSS Design In Drupal: LESS vs Sass
PPTX
Doing More With Less
PDF
Accelerated Stylesheets
PDF
Less vs sass
ODP
Compile your Style
PDF
Fasten RWD Development with Sass
PDF
Breaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
KEY
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
KEY
Sass, Compass
PDF
Adaptive theming using compass susy grid
PDF
Css to-scss
PDF
Sass and Compass - Getting Started
PDF
Haml And Sass In 15 Minutes
PPTX
PPT
LESS(CSS preprocessor)
PDF
HTML5, CSS, JavaScript Style guide and coding conventions
SASS is more than LESS
Compass, Sass, and the Enlightened CSS Developer
Wrangling the CSS Beast with Sass
Elegant CSS Design In Drupal: LESS vs Sass
Doing More With Less
Accelerated Stylesheets
Less vs sass
Compile your Style
Fasten RWD Development with Sass
Breaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Sass, Compass
Adaptive theming using compass susy grid
Css to-scss
Sass and Compass - Getting Started
Haml And Sass In 15 Minutes
LESS(CSS preprocessor)
Ad

Similar to Simple introduction Sass (20)

PDF
Pacific Northwest Drupal Summit: Basic & SASS
PDF
SASS, Compass, Gulp, Greensock
PDF
Sass & Compass (Barcamp Stuttgart 2012)
KEY
Advanced sass
PDF
SASS Preprocessor
PDF
CSS Extenders
PPTX
Sass_Cubet seminar
PPTX
Raleigh Web Design Meetup Group - Sass Presentation
PDF
Css preprocessor-140606115334-phpapp01
PDF
CSS preprocessor: why and how
PDF
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
PDF
LESS : The dynamic stylesheet language
PPTX
SCSS Implementation
PPTX
Syntactically awesome stylesheets (Sass)
PPT
UNIT 3.ppt
KEY
Intro to SASS CSS
PPTX
CSS: A Slippery Slope to the Backend
KEY
Advanced sass/compass
PPT
Learn Sass and Compass quick
Pacific Northwest Drupal Summit: Basic & SASS
SASS, Compass, Gulp, Greensock
Sass & Compass (Barcamp Stuttgart 2012)
Advanced sass
SASS Preprocessor
CSS Extenders
Sass_Cubet seminar
Raleigh Web Design Meetup Group - Sass Presentation
Css preprocessor-140606115334-phpapp01
CSS preprocessor: why and how
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
LESS : The dynamic stylesheet language
SCSS Implementation
Syntactically awesome stylesheets (Sass)
UNIT 3.ppt
Intro to SASS CSS
CSS: A Slippery Slope to the Backend
Advanced sass/compass
Learn Sass and Compass quick
Ad

Simple introduction Sass

  • 1. Sass (Syntactically Awesome Style Sheets) What is it good for…
  • 2. What is Sass? “Sass is a meta-language on top of CSS that's used to describe the style of a document cleanly and structurally, with more power than flat CSS allows. Sass both provides a simpler, more elegant syntax for CSS and implements various features that are useful for creating manageable style sheets.” - from http://sass-lang.com/ “Sass is an extension of CSS3, adding nested rules, Variables, mixins, selector inheritance, and more. It’s translated to well- formatted, standard CSS using the command line tool or a web- framework plugin.” - from internet
  • 3. a little history….. • Sass was first given life by Hampton Catlin in 2006, later supported by Natalie weizembaum and chris eppstein • Sass started life in ruby community • Sass supports two syntaxes – Indentation syntax with file ext .sass – Css compatible syntax with file ext .SCSS • Sass is free to use, require no license.
  • 4. Why use it? • Modularize (@import) • Variables for maintainability • Mixins improves reusability • Reduces redundant rules (keep it DRY) • Scalable and Maintainable Make writing style more fun….
  • 5. How do I install sass on my computer… • On Mac just run “gem install sass” • On Window download and install ruby (http://rubyinstaller.org/) on cmd prompt - run “gem install sass”
  • 6. Data Types support by sass • SassScript supports Seven data types // number example 10, 40, 50px, 60% //string example “foo”, “bar”, baz //colors example blue, #04a3f9, rgba(255, 0, 0, 0, 5) //booleans example true or false //Null example null //list example $awesome-list: “.bar” “.foo” “.odd” //maps or hash example $alist: (error: red, warn: blue, done: green)
  • 7. Lets learn to read sass • Variables // sass syntax defining the variables $red: #ff0b13 $blue-color: #091fff p color: $red //scss syntax defining the variables $red: #ff0b13; $blue-color: #091fff; p { color: $red; }
  • 8. Lets learn to read sass •Nesting Rules //sass syntax coloring the p tag inside #id “awesome” $common-color: red div#awesome p color: $common-color a color: blue &:hover color: yellow //scss syntax defining the variables $common-color: red; div#awesome { p { color: $common-color; a { color: blue; &:hover{ color: yellow; } } } }
  • 9. Lets learn to read sass Module structure with @import //sass syntax // main.sass @import navigation @import morestyle body max-width: 1200px margin: auto // “_morestyle.sass” div margin: auto padding-top: 5px //scss syntax // main.scss @import “navigation” @import “morestyle” *{ box-sizing: border-box; } body { max-width: 1200px; margin: auto; } // “_morestyle.scss” div{ margin: auto; padding-top: 5px; }
  • 10. Lets learn to read sass •chaining selectors //sass syntax $link-color: blue .content color: yellow &.main-container a color: $link-color .main-container, .mobile-container width: 100% //scss syntax $link-color: blue; .content { color: yellow; &.main-container { a { color: $link- color;} } } .main-container,.mobile- container{ width: 100 }
  • 11. Lets learn to read sass @extend directive to extend existing rules •//sass syntax $box-color: yellow .box width: 100px height: 200px background-color: $box-color .container @extend .box //scss syntax $box-color: yellow .box { width: 100px; height: 200px; } .container { @extend .box }
  • 12. Lets learn to read sass @extend directive with placeholder •//sass syntax $box-color: yellow %box width: 100px height: 200px background-color: $box-color .container @extend %box //scss syntax $box-color: yellow %box { width: 100px; height: 200px; } .container { @extend %box }
  • 13. Lets learn to read sass @mixins •//sass syntax @import compass =bs($width,$height: $width) width: $width height: $height .square +bs(100px) +clearfix //compass mixin //scss syntax @import “compass”; @mixin bs($width,$height: $width) { width: $width height: $height } .square{ @include bs(100px) @include clearfix //compass mixin }
  • 14. Lets learn to read sass @function directive •//sass syntax @import compass $color: green // function shuld return @function double($value) @return $value*2 .square width:double(100px) background-color: shade($color,60%) //scss syntax @import “compass”; $color: green; // function shuld return @function double($value) @return $value*2 .square { width:double(100px) background-color: shade($color,60%); }
  • 15. Lets learn to read sass Programmatic Logic (Math calculations with Sass) •//sass syntax .addition width: 20% + 50% .sub height: 20px - 10px .division top: (500/2) .mul width: 200px * 2 //scss syntax .addition { width: 20% + 50%; } .sub { height: 20px - 10px; } .division { top: (500/2); } .mul { width: 200px * 2; }
  • 16. Lets learn to read sass Programmatic Logic (control directive in sass) •//sass syntax $color-theme: orange $color-brand: $color-theme @if $color-theme == pink $color-brand: pink @else if $color-theme == orange $color-brand: #ff9900 .brand background-color: $color- brand //scss syntax $color-theme: orange; @if $color-theme == pink { $color-brand: pink; } @else if $color-theme == orange { $color-brand: #ff9900; } .brand { background-color: $color-brand }
  • 17. Lets learn to read sass Programmatic Logic (control directives in sass) •//sass syntax $color-theme: orange $color-brand: $color-theme @if $color-theme == pink $color-brand: pink @else if $color-theme == orange $color-brand: #ff9900 .brand background-color: $color- brand //scss syntax $color-theme: orange; @if $color-theme == pink { $color-brand: pink; } @else if $color-theme == orange { $color-brand: #ff9900; } .brand { background-color: $color-brand }
  • 18. Lets learn to read sass Programmatic Logic (@for loop in sass) •//sass syntax @for $i from 1 through 5 .div_#{$i} color: red @for $i from 6 through 10 .div_#{$i} color: green //scss syntax @for $i from 1 through 5 { .div_#{$i} { color: red; } } @for $i from 6 through 10 { .div_#{$i} { color: green; } }
  • 19. Lets learn to read sass Programmatic Logic (@each loop in sass) •//sass syntax $alist: ".odd" ".even" @each $item in $alist @if $item == '.odd' #{$item} color: green @else #{$item} color: red //scss syntax $alist: ".odd" ".even" ; @each $item in $alist { @if $item == '.odd' { #{$item} { color: green; } } @else { #{$item} { color: red; } } }
  • 20. Lets learn to read sass Programmatic Logic (@debug directive) •//sass syntax @function result($val) @debug $val @return $val * 2 .div width: result(10px) //scss syntax @function result($val) { @debug $val; @return $val * 2; } .div { width: result(10px); }
  • 21. how do you write sass 1. pick up a text editor (like atom or sublime… or anything you like) 2. choose syntax style you want to follow (sass or scss) 3. code your style rules and save the file as (.sass or .scss) like so. 4 .then comes the compilation…..
  • 22. how to compile sass • on cmd prompt type “sass <filename>.sass” the output will create new css file with “<filename>.css” (please follow step above to install sass on your mac or pc) alternatively • on cmd prompt type “compass <filename>.scss” the output will create new css file with “<filename>.css”
  • 23. how to compile sass • as a option you can use “compass watch” to continuously watch for file changes and compile them into css
  • 24. So what next…. awesome you have learn about sass… next steps • learn more complex topics (using compass) • pick up a random css file re-code it into sass • read awesome blogs from frontend developers who works on sass and coffeescript • take same online course (if you can afford it) – www.codeschool.com – www.teamtreehouse.com (i like this better)
  • 26. Lets go out there and write some sass…