Amanda Giles
http://slides.com/amanda_giles/sass
SASS is a preprocessor for CSS. It adds great functionality and better organization for your CSS files.
With SASS, you can:
2 Different syntaxes available:
Installation will depend on your OS, whether you use Ruby, and personal preferences. You can install it as:
Compass is an open-source CSS authoring framework. SASS and Compass are both written in Ruby.
Compass is:
Compass does a bunch of helpful stuff which makes it easier to write and compile SASS, in particular it has great settings for working around cross-browser quirks.
Variables can be used so you can re-use values without repeating yourself.
//Fonts
$fontPath : "http://mycompany.com/fonts";
$sans-serif: Tahoma, Verdana, Geneva, sans-serif;
$serif: "Georgia", Cambria, Times New Roman, Times, serif;
$default-font-size: 14px;
//Colors
$text-color: #474747;
$link-color: #239399;
$link-hover-color: #61d5db;
body {
font-family: $sans;
font-size: $default-font-size;
color: $text-color;
}
a, a:visited { color: $link-color; }
a:hover, a:focus { color: $link-hover-color; }
body {
font-family: Tahoma, Verdana, Geneva, sans-serif;
font-size: 14px;
color: #474747;
}
a, a:visited { color: #239399; }
a:hover, a:focus { color: #61d5db; }
CSS declarations can be nested within one another.
nav {
margin: 15px 0;
ul {
float: left;
list-style-type:none;
li {
background-color: #88888;
&:hover {
background-color: #55555;
}
}
}
}
nav {
margin: 15px 0;
}
nav ul {
float: left;
list-style-type:none;
}
nav ul li {
background-color: #88888;
}
nav ul li:hover {
background-color: #55555;
}
The @extend statement can be used to apply styles to a new selector without repeating them.
.large-text {
font-size: 24px;
line-height: 1.5;
}
.message {
border: 1px solid #008798;
}
.error {
@extend .message;
@extend .large-text;
border-color: red;
color: red;
}
.large-text, .error {
font-size: 24px;
line-height: 1.5;
}
.message, .error {
border: 1px solid #008798;
}
.error {
border-color: red;
color: red;
}
// _reset.scss
html, body, ul, ol {
margin: 0;
padding: 0;
}
/* base.scss */
@import 'reset';
body {
font: 100% Helvetica, sans-serif;
background-color: #efefef;
}
/* base.css */
html, body, ul, ol {
margin: 0;
padding: 0;
}
body {
font: 100% Helvetica, sans-serif;
background-color: #efefef;
}
// Declare the Mixin
@mixin css-gradient($from, $to) {
background-color: $to;
background-image: -webkit-gradient(linear, left top, left bottom, from($from), to($to));
background-image: -webkit-linear-gradient(top, $from, $to);
background-image: -moz-linear-gradient(top, $from, $to);
background-image: -o-linear-gradient(top, $from, $to);
background-image: linear-gradient(to bottom, $from, $to);
}
// Call the Mixin
.wrapper {
@include css-gradient(#dfdfdf,#f8f8f8);
}
@mixin vertical-align {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.wrapper .message {
@include vertical-align;
}
Operators (+, -, *, /, %) can be used in a similar manner as they are in scripting languages
nav {
$nav-width: 1000px;
$nav-links: 5;
width: $nav-width;
li {
float: left;
width: $nav-width/$nav-links - 10px;
}
}
nav {
width: 1000px;
}
nav li {
float: left;
width: 190px;
}
Compiles into:
There are a huge number of functions built into SASS. Many of these center around colors or numbers:
$link-color : #008798;
a, a:visited {
color: $link-color;
}
a:hover, a:focus {
color: lighten($link-color,25%);
}
a, a:visited {
color: #008798;
}
a:hover, a:focus {
color: #19e5ff;
}
Compiles into:
http://sass-lang.com/documentation/file.SASS_REFERENCE.html
Code Pen Example of some SASS:
http://codepen.io/maxinacube/pen/tneEq
Sass & Compass Color Functions: http://jackiebalzer.com/color