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
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
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
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
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)
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)
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)
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
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)
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
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
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
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