Getting Started with Sass & Compass

R
Rob DavarniaRob Davarnia
Sass & Compass 
with Rob Davarnia
About me 
Rob Davarnia 
@robdvr 
Full Stack Developer, Founder of ParseLabs 
Passionate about Ruby on Rails, Node.js, and Angular 
robdvr.com // parselabs.com
Sass History 
Designed by: Hampton Catlin 
Developed by: Natalie Weizenbaum, Chris Eppstein 
Since 2007 
Started as a Ruby gem
What’s Sass? 
Sass is a CSS Pre-Processor.
What’s a Pre-Processor? 
Sass File Sass Compiler CSS File
Pre-Processor Example 
p { 
color: #333; 
a { 
color: #555; 
} 
} 
p { 
color: #333; 
} 
p a { 
color: #555; 
}
Can browsers compile Sass? 
No. You need to compile it before using it.
Why Sass? 
CSS is simple, but simple is not necessarily scalable. 
Sass teaches CSS new tricks. 
Variables, Functions, and more…
Sass vs. Scss 
Different syntax 
Read more 
http://thesassway.com/editorial/sass-vs-scss-which-syntax-is-better
What’s Compass? 
A library filled with useful CSS functions built on Sass. 
ex. Cross-Browser CSS3 Rounded Corners
What’s Grunt? 
A JavaScript-based task runner to perform repetitive tasks. 
Grunt + Sass Gem help us compile Sass.
How does Grunt work? 
Grunt performs tasks you create like compiling Sass
Grunt Settings 
Gruntfile.js includes all the settings for grunt
Demo: Grunt Overview
Setting up Grunt / Folders 
robdvr.com/blog
Lab (Grunt Setup)
CSS Brush up 
// dot - classes - okay to repeat 
.wrapper 
// hashtag - ids (unique) 
#wrapper
CSS Brush up 2 
// Color 
color: #000; 
// Size 
font-size: 20px; 
// Text Alignment 
text-align: center; 
// Text Bold 
font-weight: bold; 
// Text Italic 
font-style: italic; 
// Text Underline 
text-decoration: underline; 
// Spacing - top right bottom left 
margin: 10px 20px 30px 40px; 
padding: 10px 20px 30px 40px; 
// Border 
border: 1px solid #000;
Let’s get Sassy!
Nesting 
.wrapper { 
border: 1px solid #333; 
p { 
color: #333; 
} 
} 
.wrapper { 
border: 1px solid #333; 
} 
.wrapper p { 
color: #333; 
} 
SCSS CSS
Lab (Nesting) 
<h1> Heading <span>Text</span> </h1> 
1. Create an h1 element 
2. Create a span tag nested 
3. Make the h1 color blue 
4. Make the span color red
Nesting Properties 
SCSS CSS 
.page { 
text: { 
align: center; 
transform: uppercase; 
} 
} 
.page { 
text-align: center; 
text-transform: uppercase; 
}
Parent Selector (&) 
SCSS CSS 
h3 { 
color: #000; 
&.red { 
color: #ff0000; 
} 
} 
h3 { 
color: #000; 
} 
h3.red { 
color: #ff0000; 
}
Parent Selector 2 (&) 
.sidebar { 
color: #000; 
.users & { 
color: #ff0000; 
SCSS CSS 
} 
} 
.sidebar { 
color: #000; 
} 
.users .sidebar { 
color: #ff0000; 
}
Lab (Parent Selector) 
<a href=“#” class=“nav-link”> Link1 </h1> 
<a href=“#” class=“page-link”> Link2 </h1> 
1. Copy the HTML elements above 
2. Use the nested syntax with parent selector to 
make .nav-link underlined and .page-link font-size 
20px
Nesting Pitfall 
Don’t nest more than 3-4 levels!
Variables 
$orange: #FFA500; 
p { 
color: $orange; 
} 
SCSS
Variables 2 - Strings 
$primary: 'Montserrat', sans-serif; 
body { 
font-family: $primary; 
} 
SCSS
Lab (Variables) 
1. Create a variable containing black hex color (#000) 
2. Use the variable to set a paragraph’s color 
3. Examine the output
Variables 3 - Strings 
$dark: #333; 
.wrapper { 
border: 1px solid $dark; 
p { 
color: $dark; 
} 
} 
.wrapper { 
border: 1px solid #333; 
} 
.wrapper p { 
color: #333; 
} 
SCSS CSS
Variables 4 - Lists 
$icons: facebook, twitter, instagram; 
$padding: 20px 10px 30px 40px; 
SCSS
Lab (Variables) 
1. Create a variable containing 4 margin placements 
(top right bottom left) 
2. Use the variable to set a paragraph’s margin 
3. Examine the output
Variables 5 - Null 
$icons: null; 
SCSS
Variables 6 - Overwriting 
$mainColor: #000; 
SCSS CSS 
h2 { 
$mainColor: #fff; 
background: $mainColor; 
} 
p { 
background: $mainColor; 
} 
h2 { 
background: #fff; 
} 
p { 
background: #000; 
}
Variables 7 - Names 
SCSS CSS 
$side: bottom; 
h1 { 
border-#{$side}: 1px solid #000; 
} 
.link-#{$side} { 
background: #333; 
} 
h1 { 
border-bottom: 1px solid #000; 
} 
.link-bottom { 
background: #333; 
}
Lab (Variables) 
1. Create a variable that contains value “top” 
2. Use the name variable output syntax to dynamically 
set heading2’s border value to “1px solid #000” 
3. Examine the output 
(output should be border-top: 1px solid #000)
Comments 
// This comment will not 
// get compiled 
/* This comment will compile */ 
/* This comment will compile */ 
SCSS CSS
Import 
Compiler will import typorgraphy.scss to the working file. 
@import 'typography'; 
SCSS
Partials 
Adding an underline before the filename makes a partial. 
Compiler will not compile to .css. 
_typography.scss 
@import 'typography'; 
SCSS
Lab (Partials) 
1. Create a partial named ‘buttons’ 
2. Import the buttons partial in your style.scss 
3. Set a link element’s text to underline in ‘buttons’ 
partial 
4. Save and examine the compiled output (style.css)
Mixins 
Reusable pieces of code
Why use mixins? 
.button1 { 
color: #000; 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
} 
.button2 { 
color: #bbb; 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
} 
Avoid code repetition
Basic Mixin 
@mixin button { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
} 
.button1 { 
@include button; 
color: #000; 
} 
.button2 { 
@include button; 
color: #bbb; 
}
Better with Mixins 
@mixin button { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
} 
.button1 { 
@include button; 
color: #000; 
} 
.button2 { 
@include button; 
color: #bbb; 
} 
We still have repetition 
.button1 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button2 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #bbb; 
} 
SCSS CSS
Lab (Basic Mixin) 
1. Create a basic mixin that sets the background and 
font size 
2. Use the mixin to create 2 ‘div’ elements 
3. Make the font italic on one div 
4. Save and examine the compiled output (style.css)
Avoiding Repetition 
@mixin button { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
} 
.button1, 
.button2 { 
@include button; 
} 
.button1 { 
color: #000; 
} 
.button2 { 
color: #bbb; 
} 
.button1, 
.button2 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
} 
.button1 { 
color: #000; 
} 
.button2 { 
color: #bbb; 
} 
SCSS CSS
Avoiding Repetition 
div { 
-webkit-border-radius: 5px; 
-moz-border-radius: 5px; 
border-radius: 5px; 
padding: 20px; 
border: 1px solid #000; 
}
Mixin Arguments 
Make mixins more powerful 
@mixin border-radius( $radius ) { 
-webkit-border-radius: $radius; 
-moz-border-radius: $radius; 
border-radius: $radius; 
} 
div { 
@include border-radius(5px); 
padding: 20px; 
border: 1px solid #000; 
} 
div { 
-webkit-border-radius: 5px; 
-moz-border-radius: 5px; 
border-radius: 5px; 
padding: 20px; 
border: 1px solid #000; 
} 
SCSS CSS
Mixin Argument Defaults 
@mixin border-radius( $radius: 5px ) { 
-webkit-border-radius: $radius; 
-moz-border-radius: $radius; 
border-radius: $radius; 
SCSS CSS 
} 
div { 
@include border-radius; 
} 
p { 
@include border-radius(9px); 
} 
div { 
-webkit-border-radius: 5px; 
-moz-border-radius: 5px; 
border-radius: 5px; 
} 
p { 
-webkit-border-radius: 9px; 
-moz-border-radius: 9px; 
border-radius: 9px; 
}
Multiple Mixin Arguments 
@mixin button($color, $radius) { 
-webkit-border-radius: $radius; 
-moz-border-radius: $radius; 
border-radius: $radius; 
color: $color; 
SCSS CSS 
} 
.btn { 
@include button(#333, 5px); 
border: 1px solid #000; 
} 
.btn { 
-webkit-border-radius: 5px; 
-moz-border-radius: 5px; 
border-radius: 5px; 
color: #333; 
border: 1px solid #000; 
}
Lab (Arguments Mixin) 
1. Create a mixin that takes 2 arguments. First argument 
should be for font size, and second argument should take 
the color 
2. Use the mixin to create 1 ‘a’ element 
3. Make the font size 12px and color #999 using the mixin 
4. Save and examine the compiled output (style.css)
Extend 
Pieces of code that exactly match
Why use extend? 
.button1 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
[ 
[ 
} 
.button2 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #bbb; 
}
How to extend? 
.button1 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button2 { 
@extend .button1; 
color: #bbb; 
} 
.button1, .button2 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button2 { 
color: #bbb; 
} 
SCSS CSS
Lab (Extend) 
1. Create two paragraph properties (.first-p, .second.p) 
2. Add two CSS properties to .first-p 
3. Extend .first-p on .second-p 
4. Save and examine the compiled output (style.css)
Extend Pitfalls 
Changing the parent changes all the children 
CSS Bloat! If not needed, don’t include 
User placeholder selectors to avoid making unwanted changes
Placeholder Selectors (%) 
Used for extending but can’t be used on their own
Extend without Placeholder 
.button1 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button2 { 
@extend .button1; 
color: #bbb; 
} 
.button1, .button2 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button2 { 
color: #bbb; 
} 
SCSS CSS
Extend with Placeholder 
%button { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button1 { 
@extend %button; 
} 
.button2 { 
@extend %button; 
color: #bbb; 
} 
.button1, .button2 { 
background: #e2e2e2; 
border-bottom: 1px solid #444; 
padding: 20px; 
color: #000; 
} 
.button2 { 
color: #bbb; 
} 
SCSS CSS
Lab (Placeholder) 
1. Create a paragraph property (.first-p) 
2. Create a placeholder selector 
3. Add two CSS properties to placeholder selector 
4. Extend the placeholder selector on .first-p 
5. Save and examine the compiled output (style.css)
Functions 
Return a value
Basic Function 
@function fluid($width, $total) { 
@return ($width / $total) * 100%; 
SCSS CSS 
} 
.content { 
width: fluid(600px, 900px); 
} 
.content { 
width: 66.66667%; 
}
Lab (Function) 
1. Create a function that returns (25%) 
2. Create a div selector 
3. Set the div width using the function 
4. Save and examine the compiled output (style.css)
Conditions / Comparisons
If/else statement 
$theme: light; 
SCSS CSS 
body { 
@if $theme == dark { 
color: #FFF; 
} @else { 
color: #000; 
} 
} 
body { 
color: #000; 
}
If/elseif/else statement 
$theme: light; 
SCSS CSS 
body { 
@if $theme == dark { 
color: #FFF; 
} @else if $theme == orange { 
color: #222; 
} @else { 
color: #000; 
} 
} 
body { 
color: #000; 
}
Lab (Function) 
1. Create a variable named $type set to “desktop” 
2. Create a div selector 
3. Write an if statement that checks $type 
4. Set the div’s width to 100% if the $type is NOT 
desktop
Comparisons 
== equal to 
!= not equal to 
> greater than * 
>= greater than or equal to * 
< less than * 
<= less than or equal to * 
*numbers only
For each loop
For each loop example 
SCSS 
CSS 
$icons: facebook, twitter, instagram; 
@each $icon in $icons { 
.icon-#{$icon} { 
background-image: url(#{$icon}.png); 
} 
} 
.icon-facebook { 
background-image: url(facebook.png); 
} 
.icon-twitter { 
background-image: url(twitter.png); 
} 
.icon-instagram { 
background-image: url(instagram.png); 
}
Lab (For each) 
1. Create a list of names (3 items is sufficient) 
2. Create a link selector (a element) 
3. Write a for each loop that goes through the list and 
outputs a custom class for each element 
4. Set the link’s background-image to each item’s name
For loop
For loop example 
SCSS CSS 
$i: 1; 
.link { 
background: #333; 
@for $i from 1 through 4 { 
&.link-#{$i} { 
margin-right: $i * 20px; 
} 
} 
} 
.link { 
background: #333; 
} 
.link.link-1 { 
margin-right: 20px; 
} 
.link.link-2 { 
margin-right: 40px; 
} 
.link.link-3 { 
margin-right: 60px; 
} 
.link.link-4 { 
margin-right: 80px; 
}
While loop
While loop example 
SCSS CSS 
$i: 1; 
.link { 
background: #333; 
@while $i < 4 { 
&.link-#{$i} { 
margin-right: $i * 20px; 
} 
$i: $i + 1; 
} 
} 
.link { 
background: #333; 
} 
.link.link-1 { 
margin-right: 20px; 
} 
.link.link-2 { 
margin-right: 40px; 
} 
.link.link-3 { 
margin-right: 60px; 
} 
.link.link-4 { 
margin-right: 80px; 
}
Lab (While loop) 
1. Create a number variable set to 5 
2. Create a while loop that loops based on your 
variable 
3. Output a custom class with a calculated margin-left 
… 
.image-#{$i} { 
margin-left: $i * 20px; 
} 
…
Mixins vs. Extend vs. Functions 
Mixins: similar sets of properties used with small variations 
Extend: sets properties that match exactly 
Functions: common operations that return values
Math with Sass!
Math Operations 
+ addition 
- subtraction 
* multiplication 
/ division 
% modulo
Addition example 
SCSS CSS 
.link { 
font-size: 12px + 14px; 
} 
.link { 
font-size: 26px; 
}
String Concat 
SCSS 
CSS 
.link { 
font-family: ‘Helvetica’ + ’, sans-serif’; 
} 
.link { 
font-family: ’Helvetica, sans-serif’; 
}
Math Utilities 
round($number) - round to closest whole number 
ceil($number) - round up 
floor($number) - round down 
abs($number) - absolute value 
min($list) - minimum list value 
max($list) - maximum list value 
percentage($number) - convert to percentage
Lab (Math Utilities) 
1. Create a paragraph 
2. Set the font-size to the ceiling number of 11.5px 
3. Save and review the output
Colors with Sass!
Color & Math 
$base: #333; 
SCSS CSS 
.addition { 
background: $base + #112233; 
} 
.subtraction { 
background: $base - #112233; 
} 
.multiplication { 
background: $base * 2; 
} 
.division { 
background: $base / 2; 
} 
.addition { 
background: #445566; 
} 
.subtraction { 
background: #221100; 
} 
.multiplication { 
background: #666666; 
} 
.division { 
background: #191919; 
}
Color Utilities 
color: lighten($color, 20%); 
color: darken($color, 20%); 
color: saturate($color, 20%); 
color: desaturate($color, 20%); 
color: mix(#ffff00, #107fc9); }} 
color: mix(#ffff00, #107fc9, 30%); 
color: grayscale($color); 
color: invert($color); 
color: complement($color);
More Color Utilities 
http://sass-lang.com/documentation/Sass/Script/Functions.html
Lab (Colors) 
1. Create a color variable set to black - #000 
2. Create a paragraph element 
3. Use the lighten function to make the paragraph’s 
color 50% lighter
What’s Compass? 
A library filled with useful CSS functions built on Sass. 
ex. Cross-Browser CSS3 Rounded Corners
Compass Features 
• CSS3 mixins 
• Typography mixins 
• Utilities 
• Layout Module 
• Reset Module
Compass Mixins 
• border-radius 
• opacity 
• box-shadow 
• text-shadow 
• transition 
• background-size 
• font-face 
• flexbox
All Compass Mixins 
http://compass-style.org/index/mixins/
Lab (Border Radius) 
1. Create div with black background 
2. Import Compass 
3. Using Compass’ border-radius mixin, set the div’s 
radius to 10px
Compass CSS3 Mixin Examples 
http://compass-style.org/examples/
New Compass Project 
$ gem install compass 
$ compass create <myproject> 
http://compass-style.org/install/
Watching for changes 
$ compass watch
Using Compass in Grunt 
@import ‘compass’;
Further Compass Features 
• Grid system 
• Sprite generations 
• and more 
• http://compass-style.org/
Read more… 
http://sass-lang.com/ 
http://compass-style.org 
http://gruntjs.com/
Thanks for coming! 
Q/A, Feedback, Comments, Suggestions
1 von 100

Recomendados

Work and play with SASS & Compass von
Work and play with SASS & CompassWork and play with SASS & Compass
Work and play with SASS & CompassAndreas Dantz
1.4K views63 Folien
Sass & Compass (Barcamp Stuttgart 2012) von
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)emrox
3.3K views26 Folien
Accelerated Stylesheets von
Accelerated StylesheetsAccelerated Stylesheets
Accelerated StylesheetsWynn Netherland
1.3K views147 Folien
Sass+Compass, OU: Por que CSS puro nunca mais?!? von
Sass+Compass, OU: Por que CSS puro nunca mais?!?Sass+Compass, OU: Por que CSS puro nunca mais?!?
Sass+Compass, OU: Por que CSS puro nunca mais?!?Alcides Queiroz
1.4K views80 Folien
Accelerated Native Mobile Development with the Ti gem von
Accelerated Native Mobile Development with the Ti gemAccelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gemWynn Netherland
954 views75 Folien
CSS with LESS for #jd13nl von
CSS with LESS for #jd13nlCSS with LESS for #jd13nl
CSS with LESS for #jd13nlHans Kuijpers
1.2K views34 Folien

Más contenido relacionado

Was ist angesagt?

Big Design Conference: CSS3 von
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
1.7K views141 Folien
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress" von
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"bentleyhoke
604 views21 Folien
Sass and Compass - Getting Started von
Sass and Compass - Getting StartedSass and Compass - Getting Started
Sass and Compass - Getting Startededgincvg
1.7K views29 Folien
Document von
DocumentDocument
DocumentNaveed Anjum
555 views53 Folien
Theme04 von
Theme04Theme04
Theme04Atleta De Taekwondo
450 views5 Folien
Assembling Sass von
Assembling SassAssembling Sass
Assembling SassHossain Mohammad Samrat
317 views162 Folien

Was ist angesagt?(20)

Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress" von bentleyhoke
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
bentleyhoke604 views
Sass and Compass - Getting Started von edgincvg
Sass and Compass - Getting StartedSass and Compass - Getting Started
Sass and Compass - Getting Started
edgincvg1.7K views
Simple Blue Blog Template XML 的副本 von a5494535
Simple Blue Blog Template XML 的副本Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本
a5494535588 views
CSS Preprocessors: LESS is more or look SASS-y trying von James Cryer
CSS Preprocessors: LESS is more or look SASS-y tryingCSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y trying
James Cryer1.9K views
LESS von Joe Seifi
LESSLESS
LESS
Joe Seifi13.4K views
Styling with CSS von Mike Crabb
Styling with CSSStyling with CSS
Styling with CSS
Mike Crabb1.3K views
9- Learn CSS Fundamentals / Pseudo-classes von In a Rocket
9- Learn CSS Fundamentals / Pseudo-classes9- Learn CSS Fundamentals / Pseudo-classes
9- Learn CSS Fundamentals / Pseudo-classes
In a Rocket169 views
CSSプリプロセッサの取扱説明書 von 拓樹 谷
CSSプリプロセッサの取扱説明書CSSプリプロセッサの取扱説明書
CSSプリプロセッサの取扱説明書
拓樹 谷2.4K views
Write LESS. DO more. von Eugene Nor
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
Eugene Nor658 views
Theme Kickstart von Peter
Theme KickstartTheme Kickstart
Theme Kickstart
Peter1.1K views
SASS is more than LESS von Itai Koren
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
Itai Koren1.2K views
Deep dive into sass von Knoldus Inc.
Deep dive into sassDeep dive into sass
Deep dive into sass
Knoldus Inc.1.6K views
Software programming tools for creating/managing CSS files von Dinu Suman
Software programming tools for creating/managing CSS filesSoftware programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS files
Dinu Suman1.4K views

Destacado

Front-end development automation with Grunt von
Front-end development automation with GruntFront-end development automation with Grunt
Front-end development automation with Gruntbenko
5.2K views36 Folien
Task Automatisierung mit Grunt.js von
Task Automatisierung mit Grunt.jsTask Automatisierung mit Grunt.js
Task Automatisierung mit Grunt.js3rfan
1.5K views24 Folien
Advanced sass/compass von
Advanced sass/compassAdvanced sass/compass
Advanced sass/compassNick Cooley
6.1K views58 Folien
Front End Badassery with Sass von
Front End Badassery with SassFront End Badassery with Sass
Front End Badassery with Sassjessabean
629 views24 Folien
Theming and Sass von
Theming and SassTheming and Sass
Theming and SassJames Pearce
3.5K views78 Folien
Stylesheet Wrangling with SCSS von
Stylesheet Wrangling with SCSSStylesheet Wrangling with SCSS
Stylesheet Wrangling with SCSSsforst
1.1K views18 Folien

Destacado(20)

Front-end development automation with Grunt von benko
Front-end development automation with GruntFront-end development automation with Grunt
Front-end development automation with Grunt
benko5.2K views
Task Automatisierung mit Grunt.js von 3rfan
Task Automatisierung mit Grunt.jsTask Automatisierung mit Grunt.js
Task Automatisierung mit Grunt.js
3rfan1.5K views
Advanced sass/compass von Nick Cooley
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
Nick Cooley6.1K views
Front End Badassery with Sass von jessabean
Front End Badassery with SassFront End Badassery with Sass
Front End Badassery with Sass
jessabean629 views
Stylesheet Wrangling with SCSS von sforst
Stylesheet Wrangling with SCSSStylesheet Wrangling with SCSS
Stylesheet Wrangling with SCSS
sforst1.1K views
Turbo theming: Introduction to Sass & Compass von Almog Baku
Turbo theming: Introduction to Sass & CompassTurbo theming: Introduction to Sass & Compass
Turbo theming: Introduction to Sass & Compass
Almog Baku2K views
Frontend-Entwicklung mit SASS & Compass von Andreas Dantz
Frontend-Entwicklung mit SASS & CompassFrontend-Entwicklung mit SASS & Compass
Frontend-Entwicklung mit SASS & Compass
Andreas Dantz1.1K views
Preprocessor presentation von Mario Noble
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
Mario Noble1.3K views
Performance front end language von Wei-Yi Chiu
Performance front end languagePerformance front end language
Performance front end language
Wei-Yi Chiu243 views
老成的Sass&Compass von 智遠 成
老成的Sass&Compass老成的Sass&Compass
老成的Sass&Compass
智遠 成2.7K views
Save time by using SASS/SCSS von Berit Hlubek
Save time by using SASS/SCSSSave time by using SASS/SCSS
Save time by using SASS/SCSS
Berit Hlubek3.3K views
Introduction to SASS von Jon Dean
Introduction to SASSIntroduction to SASS
Introduction to SASS
Jon Dean13K views
Learn Sass and Compass quick von Billy Shih
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quick
Billy Shih7.9K views

Similar a Getting Started with Sass & Compass

Mobile-first OOCSS, Sass & Compass at BBC Responsive News von
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
1.9K views63 Folien
CSS Extenders von
CSS ExtendersCSS Extenders
CSS ExtendersIdan Gazit
4.6K views52 Folien
Modularization css with sass von
Modularization css with sassModularization css with sass
Modularization css with sassHuiyi Yan
625 views13 Folien
SASS, Compass, Gulp, Greensock von
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockMarco Pinheiro
1.3K views43 Folien
Doing More With Less von
Doing More With LessDoing More With Less
Doing More With LessDavid Engel
1.3K views37 Folien
Wrangling the CSS Beast with Sass von
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with SassRob Friesel
1.4K views117 Folien

Similar a Getting Started with Sass & Compass(20)

CSS Extenders von Idan Gazit
CSS ExtendersCSS Extenders
CSS Extenders
Idan Gazit4.6K views
Modularization css with sass von Huiyi Yan
Modularization css with sassModularization css with sass
Modularization css with sass
Huiyi Yan625 views
SASS, Compass, Gulp, Greensock von Marco Pinheiro
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, Greensock
Marco Pinheiro1.3K views
Doing More With Less von David Engel
Doing More With LessDoing More With Less
Doing More With Less
David Engel1.3K views
Wrangling the CSS Beast with Sass von Rob Friesel
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
Rob Friesel1.4K views
Using Sass - Building on CSS von Sayanee Basu
Using Sass - Building on CSSUsing Sass - Building on CSS
Using Sass - Building on CSS
Sayanee Basu1K views
LESS : The dynamic stylesheet language von Katsunori Tanaka
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet language
Katsunori Tanaka3.3K views
CSS 開發加速指南-Sass & Compass von Lucien Lee
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
Lucien Lee2.5K views
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass von Claudina Sarahe
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Claudina Sarahe3K views
Rapid Prototyping von Even Wu
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Even Wu1.4K views
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version) von Adam Darowski
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
Adam Darowski1.1K views
Advanced Technology for Web Application Design von Bryce Kerley
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
Bryce Kerley728 views

Último

DevsRank von
DevsRankDevsRank
DevsRankdevsrank786
11 views1 Folie
Unleash The Monkeys von
Unleash The MonkeysUnleash The Monkeys
Unleash The MonkeysJacob Duijzer
7 views28 Folien
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... von
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...Deltares
6 views15 Folien
Citi TechTalk Session 2: Kafka Deep Dive von
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Diveconfluent
17 views60 Folien
SAP FOR CONTRACT MANUFACTURING.pdf von
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdfVirendra Rai, PMP
11 views2 Folien
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... von
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...Deltares
13 views34 Folien

Último(20)

DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... von Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
Citi TechTalk Session 2: Kafka Deep Dive von confluent
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
confluent17 views
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... von Deltares
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
Deltares13 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema von Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM... von Deltares
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
Deltares7 views
MariaDB stored procedures and why they should be improved von Federico Razzoli
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... von Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... von Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri711 views
Software evolution understanding: Automatic extraction of software identifier... von Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea... von Safe Software
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Safe Software412 views
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... von Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares11 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... von Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)... von Deltares
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...
Deltares9 views
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker von Deltares
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - ParkerDSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
Deltares9 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... von Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares9 views

Getting Started with Sass & Compass

  • 1. Sass & Compass with Rob Davarnia
  • 2. About me Rob Davarnia @robdvr Full Stack Developer, Founder of ParseLabs Passionate about Ruby on Rails, Node.js, and Angular robdvr.com // parselabs.com
  • 3. Sass History Designed by: Hampton Catlin Developed by: Natalie Weizenbaum, Chris Eppstein Since 2007 Started as a Ruby gem
  • 4. What’s Sass? Sass is a CSS Pre-Processor.
  • 5. What’s a Pre-Processor? Sass File Sass Compiler CSS File
  • 6. Pre-Processor Example p { color: #333; a { color: #555; } } p { color: #333; } p a { color: #555; }
  • 7. Can browsers compile Sass? No. You need to compile it before using it.
  • 8. Why Sass? CSS is simple, but simple is not necessarily scalable. Sass teaches CSS new tricks. Variables, Functions, and more…
  • 9. Sass vs. Scss Different syntax Read more http://thesassway.com/editorial/sass-vs-scss-which-syntax-is-better
  • 10. What’s Compass? A library filled with useful CSS functions built on Sass. ex. Cross-Browser CSS3 Rounded Corners
  • 11. What’s Grunt? A JavaScript-based task runner to perform repetitive tasks. Grunt + Sass Gem help us compile Sass.
  • 12. How does Grunt work? Grunt performs tasks you create like compiling Sass
  • 13. Grunt Settings Gruntfile.js includes all the settings for grunt
  • 15. Setting up Grunt / Folders robdvr.com/blog
  • 17. CSS Brush up // dot - classes - okay to repeat .wrapper // hashtag - ids (unique) #wrapper
  • 18. CSS Brush up 2 // Color color: #000; // Size font-size: 20px; // Text Alignment text-align: center; // Text Bold font-weight: bold; // Text Italic font-style: italic; // Text Underline text-decoration: underline; // Spacing - top right bottom left margin: 10px 20px 30px 40px; padding: 10px 20px 30px 40px; // Border border: 1px solid #000;
  • 20. Nesting .wrapper { border: 1px solid #333; p { color: #333; } } .wrapper { border: 1px solid #333; } .wrapper p { color: #333; } SCSS CSS
  • 21. Lab (Nesting) <h1> Heading <span>Text</span> </h1> 1. Create an h1 element 2. Create a span tag nested 3. Make the h1 color blue 4. Make the span color red
  • 22. Nesting Properties SCSS CSS .page { text: { align: center; transform: uppercase; } } .page { text-align: center; text-transform: uppercase; }
  • 23. Parent Selector (&) SCSS CSS h3 { color: #000; &.red { color: #ff0000; } } h3 { color: #000; } h3.red { color: #ff0000; }
  • 24. Parent Selector 2 (&) .sidebar { color: #000; .users & { color: #ff0000; SCSS CSS } } .sidebar { color: #000; } .users .sidebar { color: #ff0000; }
  • 25. Lab (Parent Selector) <a href=“#” class=“nav-link”> Link1 </h1> <a href=“#” class=“page-link”> Link2 </h1> 1. Copy the HTML elements above 2. Use the nested syntax with parent selector to make .nav-link underlined and .page-link font-size 20px
  • 26. Nesting Pitfall Don’t nest more than 3-4 levels!
  • 27. Variables $orange: #FFA500; p { color: $orange; } SCSS
  • 28. Variables 2 - Strings $primary: 'Montserrat', sans-serif; body { font-family: $primary; } SCSS
  • 29. Lab (Variables) 1. Create a variable containing black hex color (#000) 2. Use the variable to set a paragraph’s color 3. Examine the output
  • 30. Variables 3 - Strings $dark: #333; .wrapper { border: 1px solid $dark; p { color: $dark; } } .wrapper { border: 1px solid #333; } .wrapper p { color: #333; } SCSS CSS
  • 31. Variables 4 - Lists $icons: facebook, twitter, instagram; $padding: 20px 10px 30px 40px; SCSS
  • 32. Lab (Variables) 1. Create a variable containing 4 margin placements (top right bottom left) 2. Use the variable to set a paragraph’s margin 3. Examine the output
  • 33. Variables 5 - Null $icons: null; SCSS
  • 34. Variables 6 - Overwriting $mainColor: #000; SCSS CSS h2 { $mainColor: #fff; background: $mainColor; } p { background: $mainColor; } h2 { background: #fff; } p { background: #000; }
  • 35. Variables 7 - Names SCSS CSS $side: bottom; h1 { border-#{$side}: 1px solid #000; } .link-#{$side} { background: #333; } h1 { border-bottom: 1px solid #000; } .link-bottom { background: #333; }
  • 36. Lab (Variables) 1. Create a variable that contains value “top” 2. Use the name variable output syntax to dynamically set heading2’s border value to “1px solid #000” 3. Examine the output (output should be border-top: 1px solid #000)
  • 37. Comments // This comment will not // get compiled /* This comment will compile */ /* This comment will compile */ SCSS CSS
  • 38. Import Compiler will import typorgraphy.scss to the working file. @import 'typography'; SCSS
  • 39. Partials Adding an underline before the filename makes a partial. Compiler will not compile to .css. _typography.scss @import 'typography'; SCSS
  • 40. Lab (Partials) 1. Create a partial named ‘buttons’ 2. Import the buttons partial in your style.scss 3. Set a link element’s text to underline in ‘buttons’ partial 4. Save and examine the compiled output (style.css)
  • 42. Why use mixins? .button1 { color: #000; background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; } .button2 { color: #bbb; background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; } Avoid code repetition
  • 43. Basic Mixin @mixin button { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; } .button1 { @include button; color: #000; } .button2 { @include button; color: #bbb; }
  • 44. Better with Mixins @mixin button { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; } .button1 { @include button; color: #000; } .button2 { @include button; color: #bbb; } We still have repetition .button1 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button2 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #bbb; } SCSS CSS
  • 45. Lab (Basic Mixin) 1. Create a basic mixin that sets the background and font size 2. Use the mixin to create 2 ‘div’ elements 3. Make the font italic on one div 4. Save and examine the compiled output (style.css)
  • 46. Avoiding Repetition @mixin button { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; } .button1, .button2 { @include button; } .button1 { color: #000; } .button2 { color: #bbb; } .button1, .button2 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; } .button1 { color: #000; } .button2 { color: #bbb; } SCSS CSS
  • 47. Avoiding Repetition div { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; padding: 20px; border: 1px solid #000; }
  • 48. Mixin Arguments Make mixins more powerful @mixin border-radius( $radius ) { -webkit-border-radius: $radius; -moz-border-radius: $radius; border-radius: $radius; } div { @include border-radius(5px); padding: 20px; border: 1px solid #000; } div { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; padding: 20px; border: 1px solid #000; } SCSS CSS
  • 49. Mixin Argument Defaults @mixin border-radius( $radius: 5px ) { -webkit-border-radius: $radius; -moz-border-radius: $radius; border-radius: $radius; SCSS CSS } div { @include border-radius; } p { @include border-radius(9px); } div { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } p { -webkit-border-radius: 9px; -moz-border-radius: 9px; border-radius: 9px; }
  • 50. Multiple Mixin Arguments @mixin button($color, $radius) { -webkit-border-radius: $radius; -moz-border-radius: $radius; border-radius: $radius; color: $color; SCSS CSS } .btn { @include button(#333, 5px); border: 1px solid #000; } .btn { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #333; border: 1px solid #000; }
  • 51. Lab (Arguments Mixin) 1. Create a mixin that takes 2 arguments. First argument should be for font size, and second argument should take the color 2. Use the mixin to create 1 ‘a’ element 3. Make the font size 12px and color #999 using the mixin 4. Save and examine the compiled output (style.css)
  • 52. Extend Pieces of code that exactly match
  • 53. Why use extend? .button1 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; [ [ } .button2 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #bbb; }
  • 54. How to extend? .button1 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button2 { @extend .button1; color: #bbb; } .button1, .button2 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button2 { color: #bbb; } SCSS CSS
  • 55. Lab (Extend) 1. Create two paragraph properties (.first-p, .second.p) 2. Add two CSS properties to .first-p 3. Extend .first-p on .second-p 4. Save and examine the compiled output (style.css)
  • 56. Extend Pitfalls Changing the parent changes all the children CSS Bloat! If not needed, don’t include User placeholder selectors to avoid making unwanted changes
  • 57. Placeholder Selectors (%) Used for extending but can’t be used on their own
  • 58. Extend without Placeholder .button1 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button2 { @extend .button1; color: #bbb; } .button1, .button2 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button2 { color: #bbb; } SCSS CSS
  • 59. Extend with Placeholder %button { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button1 { @extend %button; } .button2 { @extend %button; color: #bbb; } .button1, .button2 { background: #e2e2e2; border-bottom: 1px solid #444; padding: 20px; color: #000; } .button2 { color: #bbb; } SCSS CSS
  • 60. Lab (Placeholder) 1. Create a paragraph property (.first-p) 2. Create a placeholder selector 3. Add two CSS properties to placeholder selector 4. Extend the placeholder selector on .first-p 5. Save and examine the compiled output (style.css)
  • 62. Basic Function @function fluid($width, $total) { @return ($width / $total) * 100%; SCSS CSS } .content { width: fluid(600px, 900px); } .content { width: 66.66667%; }
  • 63. Lab (Function) 1. Create a function that returns (25%) 2. Create a div selector 3. Set the div width using the function 4. Save and examine the compiled output (style.css)
  • 65. If/else statement $theme: light; SCSS CSS body { @if $theme == dark { color: #FFF; } @else { color: #000; } } body { color: #000; }
  • 66. If/elseif/else statement $theme: light; SCSS CSS body { @if $theme == dark { color: #FFF; } @else if $theme == orange { color: #222; } @else { color: #000; } } body { color: #000; }
  • 67. Lab (Function) 1. Create a variable named $type set to “desktop” 2. Create a div selector 3. Write an if statement that checks $type 4. Set the div’s width to 100% if the $type is NOT desktop
  • 68. Comparisons == equal to != not equal to > greater than * >= greater than or equal to * < less than * <= less than or equal to * *numbers only
  • 70. For each loop example SCSS CSS $icons: facebook, twitter, instagram; @each $icon in $icons { .icon-#{$icon} { background-image: url(#{$icon}.png); } } .icon-facebook { background-image: url(facebook.png); } .icon-twitter { background-image: url(twitter.png); } .icon-instagram { background-image: url(instagram.png); }
  • 71. Lab (For each) 1. Create a list of names (3 items is sufficient) 2. Create a link selector (a element) 3. Write a for each loop that goes through the list and outputs a custom class for each element 4. Set the link’s background-image to each item’s name
  • 73. For loop example SCSS CSS $i: 1; .link { background: #333; @for $i from 1 through 4 { &.link-#{$i} { margin-right: $i * 20px; } } } .link { background: #333; } .link.link-1 { margin-right: 20px; } .link.link-2 { margin-right: 40px; } .link.link-3 { margin-right: 60px; } .link.link-4 { margin-right: 80px; }
  • 75. While loop example SCSS CSS $i: 1; .link { background: #333; @while $i < 4 { &.link-#{$i} { margin-right: $i * 20px; } $i: $i + 1; } } .link { background: #333; } .link.link-1 { margin-right: 20px; } .link.link-2 { margin-right: 40px; } .link.link-3 { margin-right: 60px; } .link.link-4 { margin-right: 80px; }
  • 76. Lab (While loop) 1. Create a number variable set to 5 2. Create a while loop that loops based on your variable 3. Output a custom class with a calculated margin-left … .image-#{$i} { margin-left: $i * 20px; } …
  • 77. Mixins vs. Extend vs. Functions Mixins: similar sets of properties used with small variations Extend: sets properties that match exactly Functions: common operations that return values
  • 79. Math Operations + addition - subtraction * multiplication / division % modulo
  • 80. Addition example SCSS CSS .link { font-size: 12px + 14px; } .link { font-size: 26px; }
  • 81. String Concat SCSS CSS .link { font-family: ‘Helvetica’ + ’, sans-serif’; } .link { font-family: ’Helvetica, sans-serif’; }
  • 82. Math Utilities round($number) - round to closest whole number ceil($number) - round up floor($number) - round down abs($number) - absolute value min($list) - minimum list value max($list) - maximum list value percentage($number) - convert to percentage
  • 83. Lab (Math Utilities) 1. Create a paragraph 2. Set the font-size to the ceiling number of 11.5px 3. Save and review the output
  • 85. Color & Math $base: #333; SCSS CSS .addition { background: $base + #112233; } .subtraction { background: $base - #112233; } .multiplication { background: $base * 2; } .division { background: $base / 2; } .addition { background: #445566; } .subtraction { background: #221100; } .multiplication { background: #666666; } .division { background: #191919; }
  • 86. Color Utilities color: lighten($color, 20%); color: darken($color, 20%); color: saturate($color, 20%); color: desaturate($color, 20%); color: mix(#ffff00, #107fc9); }} color: mix(#ffff00, #107fc9, 30%); color: grayscale($color); color: invert($color); color: complement($color);
  • 87. More Color Utilities http://sass-lang.com/documentation/Sass/Script/Functions.html
  • 88. Lab (Colors) 1. Create a color variable set to black - #000 2. Create a paragraph element 3. Use the lighten function to make the paragraph’s color 50% lighter
  • 89. What’s Compass? A library filled with useful CSS functions built on Sass. ex. Cross-Browser CSS3 Rounded Corners
  • 90. Compass Features • CSS3 mixins • Typography mixins • Utilities • Layout Module • Reset Module
  • 91. Compass Mixins • border-radius • opacity • box-shadow • text-shadow • transition • background-size • font-face • flexbox
  • 92. All Compass Mixins http://compass-style.org/index/mixins/
  • 93. Lab (Border Radius) 1. Create div with black background 2. Import Compass 3. Using Compass’ border-radius mixin, set the div’s radius to 10px
  • 94. Compass CSS3 Mixin Examples http://compass-style.org/examples/
  • 95. New Compass Project $ gem install compass $ compass create <myproject> http://compass-style.org/install/
  • 96. Watching for changes $ compass watch
  • 97. Using Compass in Grunt @import ‘compass’;
  • 98. Further Compass Features • Grid system • Sprite generations • and more • http://compass-style.org/
  • 99. Read more… http://sass-lang.com/ http://compass-style.org http://gruntjs.com/
  • 100. Thanks for coming! Q/A, Feedback, Comments, Suggestions