SASS is just a Ruby gem
$ gem install sass
$ gem install compass
Easy, right?
$ compass create <projectname>
/config.rb
is the control panel for compass settings
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
Compass offers a ton of of settings for you to configure: http://compass-style.org/help/tutorials/configuration-reference
$red: #b75548;
a {
color: $red;
}
compiles to:
a {
color: #b75548;
}
instead of pulling out your calculator...
$baseFont: 16;
body {
font-size: 16px;
}
.content p {
font-size: 0.8125em; /* 13px / 16px */
}
@function em($value, $context:$baseFont) {
@return ($value / $context) * 1em;
}
.content p {
font-size: em(13);
}
compiles to:
.content p {
font-size: 0.8125em;
}
Sometimes (oftentimes) you want to repeat a set of styles
.content p {
font-family: "Goudy Old Style", Garamond,
"Big Caslon", "Times New Roman", serif;
}
yeah, no thanks
$goudy: "Goudy Old Style", Garamond,
"Big Caslon", "Times New Roman", serif;
@mixin fontSerif($weight:normal) {
font-family: $goudy;
font-weight: $weight;
}
.content p {
@include fontSerif(700);
}
compiles to:
.content p {
font-family: "Goudy Old Style", Garamond,
"Big Caslon", "Times New Roman", serif;
font-weight: 700;
}
.square {
background: red;
width: 200px;
height: 200px;
border: 3px solid #fff;
}
.circle {
background: red;
width: 200px;
height: 200px;
border: 3px solid #fff;
border-radius: 100%;
}
.square {
background: red;
width: 200px;
height: 200px;
border: 3px solid #fff;
}
.circle {
@extend .square;
border-radius: 100%;
}
compiles to:
.square, .circle {
background: red;
width: 200px;
height: 200px;
border: 3px solid #fff;
}
.cricle {
border-radius: 100%;
}
what if there's css we don't need?
.button {
padding: 5px 20px;
border: 1px solid #fff;
font-family: "Helvetica", arial, sans-serif;
}
.button-orange {
@extend .button;
background: #ffbb6b;
}
%button {
padding: 5px 20px;
border: 1px solid #fff;
font-family: "Helvetica", arial, sans-serif;
}
.button-orange {
@extend %button;
background: #ffbb6b;
}
configure compass output based on your environment needs
if environment == :development
line_comments = true
output_style = :expanded
line_comments = false
end
if environment == :production
line_comments = true
output_style = :compressed
end
then fire off your compass task
compass compile -e production --force
know what's not fun? http requests
@import url('/css/typography.css');
@import url('/css/layout.css');
@import url('/css/color.css');
also not fun? browsing 6,000 lines of css to edit one line
no more imports, file lengths are manageable & names are descriptive. no css in sceen.scss
sass
├── component
│ ├── _columns.scss
│ └── _signup.scss
├── lib
│ ├── _animation.scss
│ ├── _carousel.scss
│ ├── _mediaQueries.scss
│ └── _normalize.scss
├── screen.scss
└── section
├── _faq.scss
├── _feedback.scss
├── _footer.scss
└── _sidebar.scss
// utility / helper
@import "compass";
@import "modules/_defaults";
@import "modules/_helpers";
// libraries
@import "lib/_mediaQueries";
@import "lib/_normalize";
// components
@import "component/_layout";
@import "component/_navigation";
a {
color: pink;
a &:hover {
color: darken(pink, 20%);
}
}
percentage( 100px / 50px ) => 200%
Reference: http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html
i hate doing math
// layout
$siteWidth: 1000px;
$mainColumnWidth: 665px;
$mainColumnSpacing: 20px;
%column-left-of-two {
width: $mainColumnWidth;
padding: 0 $mainColumnSpacing 0 0;
float: left;
}
// sidebar
%column-right-of-two {
width: $siteWidth - ($mainColumnWidth + $mainColumnSpacing );
float: left;
padding: 0 0 0 $mainColumnSpacing;
}
don't be afraid to be verbose
$red: #ff0000;
a {
color: $red;
}
.button {
color: $red;
}
.container {
border: 1px solid $red;
}
instead
// colors
$red: #ff0000;
// color reference
$mainAccent: $red;
a {
color: $mainAccent;
}
.button {
color: $mainAccent;
}
.container {
border: 1px solid $mainAccent;
}
debugging can be awesome