Part I: Expressions, Variables and functions
Expressions
(maths)
0.333333
1/3
0.333333 %
( 1/3 ) %
12
1 + 4 + 7
Variables
Assignment:
$variable: 12px;
$colour: #FF0022;
Usage:
p {
font-size: $variable;
color: $colour;
}
Output:
p {
font-size: 12px;
color: #FF0022;
}
Variables II: With Expressions
$block-height: 100px;
$number-of-blocks: 3;
.block-container {
height: $block-height * $number-of-blocks;
}
Note that words are separated by hyphens ( - ), like in CSS
Variables III: repetition
Replace duplicated colours with a useful variable name
They only need updating in one place
Functions
-
Readability
-
Repetition
-
Complicatedness
Functions II: Anatomy
name( input, more-input )
Functions III: Example
pow( 4, 2 )
16
Styling a Button
Different styles in different states:
-
hovering
-
clicking
-
disabled
-
highlighted
Colour Functions!
http://sass-lang.com/documentation/Sass/Script/Functions.html
lighten( $colour, 10% )
darken( $colour, 10% )
desaturate( $colour, 10% )
transparentize( $colour, 10% )
hue( $colour, $degrees )