...and are governed by the cascading algorithm.
selector {
property: value;
property: value;
}
Benefits
Benefits
Benefits
Benefits
Challenges
Challenges
Challenges
Challenges
Challenges
Basics
Sass is an extension of CSS that adds power and elegance to the basic language. It allows you to use variables, nested rules, mixins, inline imports, and more, all with a fully CSS-compatible syntax. Sass helps keep large stylesheets well-organized, and get small stylesheets up and running quickly, particularly with the help of the Compass style library.
Basics
h1
font-size: 30px
line-height: 36px
color: #ca0164
p
font-size: 18px
line-height: 24px
color: #333
h1 {
font-size: 30px;
line-height: 36px;
color: #ca0164;
}
p {
font-size: 18px;
line-height: 24px;
color: #333;
}
Basics
Basics
Nesting
.site-header {
background: #efefef;
margin-bottom: 65px;
.header-wrap {
padding: 28px 100px;
max-width: 1200px;
margin: 0 auto;
}
.site-title {
max-width: 85px;
}
}
.site-header {
background: #efefef;
margin-bottom: 65px;
}
.site-header .header-wrap {
padding: 28px 100px;
max-width: 1200px;
margin: 0 auto;
}
.site-header .site-title {
max-width: 85px;
}
Nesting
Nesting
Nesting
p {
font: {
size: 18px;
family: Arial, sans-serif;
weight: 400;
}
color: #333;
margin: 0 0 20px;
}
p {
font-size: 18px;
font-family: Arial, sans-serif;
font-weight: 400;
color: #333;
margin: 0 0 20px;
}
Nesting
.hero {
background: {
color: #eaeaea;
size: cover;
image: url("img.png");
repeat: no-repeat;
position: center;
}
}
.hero {
background-color: #eaeaea;
background-size: cover;
background-image: url("img.png");
background-repeat: no-repeat;
background-position: center;
}
Nesting
& is a special character in Sass that references the parent selector of a nested item.
Nesting
a {
font-weight: 700;
color: purple;
text-decoration: none;
border-bottom: 3px solid purple;
&:hover {
color: blue;
border-color: blue;
}
&.alert {
color: red;
border-color: red;
}
}
a {
font-weight: 700;
color: purple;
text-decoration: none;
border-bottom: 3px solid purple;
}
a:hover {
color: blue;
border-color: blue;
}
a.alert {
color: red;
border-color: red;
}
Nesting
.header-wrap {
padding: 28px 100px;
max-width: 1200px;
margin: 0 auto;
@media screen and (max-width: 1199px) {
padding: 22px 60px;
}
@media screen and (max-width: 769px) {
padding: 16px 40px;
}
@media screen and (max-width: 450px) {
padding: 12px 30px;
}
}
Nesting
.header-wrap {
padding: 28px 100px;
max-width: 1200px;
margin: 0 auto;
}
@media screen and (max-width: 1199px) {
.header-wrap {
padding: 22px 60px;
}
}
@media screen and (max-width: 769px) {
.header-wrap {
padding: 16px 40px;
}
}
@media screen and (max-width: 450px) {
.header-wrap {
padding: 12px 30px;
}
}
Allow defining values once for use throughout a style sheet.
Variables
/* colors */
$dark: #333;
$light: #e9e9e9;
$accent: #ca0164;
/* fonts */
$serif: Georgia, serif;
$sans: Arial, sans-serif;
$mono: "Courier New", monospace, sans-serif;
/* font weights */
$light: 200;
$reg: 400;
$bold: 700;
Variables
p {
font: {
size: 18px;
family: $sans;
weight: $reg;
}
color: $dark;
margin: 0 0 20px;
}
p {
font-size: 18px;
font-family: Arial, sans-serif;
font-weight: 400;
color: #333;
margin: 0 0 20px;
}
Variables
Variables
Mixins
/* Displays as block element and centers it */
@mixin center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
/* Defines base style for headlines */
@mixin headline {
font: {
size: 22px;
family: $serif;
weight: bold;
}
text-transform: uppercase;
margin: 0 0 20px;
}
Mixins
h2 {
@include center-block;
@include headline;
color: $accent;
}
h3 {
@include headline;
color: $dark;
}
h2 {
display: block;
margin-left: auto;
margin-right: auto;
font-size: 22px;
font-family: $serif;
font-weight: bold;
text-transform: uppercase;
margin: 0 0 20px;
color: #ca0164;
}
h3 {
font-size: 22px;
font-family: $serif;
font-weight: bold;
text-transform: uppercase;
color: #333;
}
Mixins
/* Defines base style for headlines */
@mixin headline($color) {
font: {
size: 22px;
family: $serif;
weight: bold;
}
color: $color;
text-transform: uppercase;
margin: 0 0 20px;
}
Mixins
h2 {
@include center-block;
@include headline($accent);
}
h3 {
@include headline($dark);
}
h2 {
display: block;
margin-left: auto;
margin-right: auto;
font-size: 22px;
font-family: $serif;
font-weight: bold;
text-transform: uppercase;
margin: 0 0 20px;
color: #ca0164;
}
h3 {
font-size: 22px;
font-family: $serif;
font-weight: bold;
text-transform: uppercase;
color: #333;
}
Mixins
/* browser prefix for displaying flexbox */
@mixin flex {
display: -webkit-flex;
display: flex;
}
/* browser prefix for border-radius */
@mixin radius($number) {
-webkit-border-radius: $number;
-moz-border-radius: $number;
border-radius: $number;
}
Note: border-radius has 95% support without prefixes and doesn't really require them anymore, it's just a great classic example of how to use mixins to your advantage.
Mixins
Write your most common mixins once and reuse across projects.
Sass supports standard math operators like:
Operators
.container {
width: 100%;
}
section.main {
float: left;
width: 600px / 960px * 100%;
}
section.sidebar {
float: right;
width: 300px / 960px * 100%;
}
.container {
width: 100%;
}
section.main {
float: left;
width: 62.5%;
}
section.sidebar {
float: right;
width: 31.25%;
}
Partials
Partials
@import "typography/copy";
@import "typography/headings";
Comments
/* This is a multi-line comment that will compile to the CSS output. */
// This is a single-line comment that will not compile to the CSS output.
/* This is a multi-line comment that will compile to the CSS output. */
Installation
Installation
gem install sass
If that doesn't work...
sudo gem install sass
Installation
M = Mac; W = Windows; L = Linux
Compiling
sass --watch [path]
Compiling
gem install compass
cd /your/project/path
compass watch
Setting Up Themes
Setting Up Themes
Setting Up Themes