Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
I'm Erin Depew
Tell us about yourself.
header {
background-color: #f90000;
color: #fff;
}
header a { color: #fff; }
With Sass Variables:
$brandColor: #f90000;
$accentColor: #fff;
header {
background-color: $brandColor;
color: $accentColor;
}
header a { color: $accentColor; }
$brandColor: #f90000;
$accentColor: #fff;
header {
background-color: $brandColor;
color: $accentColor;
}
header a { color: $accentColor; }
With Sass Nesting:
$brandColor: #f90000;
$accentColor: #fff;
header {
background-color: $brandColor;
color: $accentColor;
a {
color: $accentColor;
}}
$brandColor: #f90000;
$accentColor: #fff;
@mixin default-button {
width: 100%;
display: block;
text-align: center;
}
.button--fancy {
@include default-button;
background: $brandColor;
color: $accentColor;
}
.button--fancy {
background: #f90000;
color: #fff;
width: 100%;
display: block;
text-align: center;
}
$ cd ../
Go to your home directory:
$ cd /
Go to a specific folder:
$ cd Users/cfarman/Sites/gdi-sass
List files in a directory:
$ ls
ruby -v
Install the Sass gem by using Terminal or Git Bash:
gem install sass
We need to structure our stylesheets before we can compile them.
We need to compile our Sass files to make the CSS work in the browser.
First, navigate via the command line to your /stylesheets directory in the "practice" folder.
Then type:
$ sass --watch scss:css
$ sass --watch scss:css
--watch look for changes to our .scss files, and compile them to css if they have updates
scss is the location of the Sass files
css is the location for the compiled Sass (aka CSS) files
Sass input:
header {
color: black;
nav {
background: red;
a { color: white; }
}
CSS output:
header { color: black; }
header nav { background: red; }
header nav a { color: white; }
Sass input:
nav {
background: red;
a {
color: white;
&:hover { text-decoration: underline; }
}
}
CSS output:
nav { background: red; }
nav a { color: white; }
nav a:hover { text-decoration: underline; }
Prefixing:
p {
body.no-touch & {
display: none; // hide the message if not on a touch device
}
}
BEM syntax:
.header {
&__title{
font-size: 20px;
color: black;
}
}
Stand up and stretch - we'll resume in 5 minutes
#2a79af
Georgia, Times, "Times New Roman", serif;
1.667em
Define once, use everywhere
//define using dollar sign
$brandColor: #f90000;
$mainTextcolor: #fff;
$accentColor: #ccc;
$brandColor: #f90000; // red
$mainTextcolor: #fff; // white
$accentColor: #ccc; // grey
header {
color: $mainTextColor;
background-color: $brandColor;
}
.content {
color: $mainTextColor;
background-color: $accentColor;
}
footer {
color: $accentColor;
background-color: $brandColor;
}
@import "_utilities";
You can download tools to highlight your Sass properly in Sublime Text:
With CSS you have to be explicit about everything, including numbers. With Sass, you can write math to calculate numbers for you:
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division* |
*division is special, check the documentation link for why and how
Sass input:
$layoutWidth: 960px;
#sidebar {
width: $layoutWidth/3;
}
CSS output:
#sidebar {
width: 320px;
}
Sass input:
$layoutWidth: 960px;
$defaultPadding: 16px;
#main {
padding: $defaultPadding;
width: $layoutWidth - $defaultPadding*2;
}
CSS output:
#main {
padding: 16px;
width: 928px;
}
$layoutWidth: 960px;
$navWidth: $layoutWidth/3;
footer {
width: ($layoutWidth - 20px);
}
Lighten function
Sass input:
$linkColor: #000;
$linkShadow: lighten(#000, 40%);
a {
color: $linkColor;
text-shadow: $linkShadow;
}
CSS output:
a {
color: #000;
text-shadow: #666;
}
Darken function
Sass input:
$background: #ff0000; // red
$text: darken($background,50%);
body {
color: $text;
background: $background;
}
CSS output:
body {
color: #990000;
background: #ff0000;
}
Grayscale function
Sass input:
$background: #ff0000; // red
$text: darken($background,50%);
body {
background: grayscale(#f00);
color: grayscale(darken(#f00, 50%));
}
CSS output:
body {
background: #000;
color: #808080;
}
lighten(#000, 20%)
darken(#eee, 30%)
grayscale(#2a79af)
saturate(#2a79af, 40%)
invert(#2a79af)
One or more style rules that can be reused
Sass input:
@mixin dropshadow($text) {
color: $text;
text-shadow: 2px 4px lighten($text, 50%);
}
p {
@include dropshadow(black);
}
CSS output:
p {
color: black;
text-shadow: 2px 4px #808080;
}
@mixin name {
property: value;
}
@mixin example($argument) {
property: value;
property: $argument;
}