On Github rmjames / Intro-to-Sass
Created by RobertJames / @bkrjames
Sass is one of many CSS preprocessors .
Less
Stylus
Sass
Modularize your project into multiple files called partials in developement environment.
├── components │ ├── _buttons.scss │ ├── forms.scss │ └── _navigation.scss ├── config │ ├── _extends.scss │ ├── _functions.scss │ ├── _mixins.scss │ └── _variables.scss ├── layout │ ├── _footer.scss │ ├── _grids.scss │ ├── _header.scss │ └── _sidebar.scss └── main.scss
All import to one .scss file
Large Community of Libraries and Frameworks
Compilations of large files can sometimes be slow
However, when sass imports files it caches them, which greatly increases the speed
$color-header: #b4aaf4; header {background: $color-header;}
nav { background: #000; li { display: inline;} }
nav { background: #000; } nav li { display: inline; }
Are .scss files preceeded with an underscore => _filename.scss
├── ie.scss ├── partials │ ├── _base.scss │ ├── _fonts.scss │ ├── _forms.scss │ ├── _header.scss │ ├── _layout.scss │ ├── _menu.scss │ └── _mixins.scss ├── print.scss └── screen.scss
addition +, subtraction -, multiplication *, division /, and modulo %)
.foo {width: 100px + 30px * 3/ 2 - 25px;}
CSS Output
.foo {width: 120px;}
.avatar { background-color: red; height: 120px; margin: 40px; width: 120px; @at-root { @keyframes fade { 0% { transform: scale(1.0); } 25% { transform: scale(1.1); } 50% { transform: scale(1.0); } 75% { transform: scale(1.2); } 100% { transform: scale(1.1); } } } &:hover { animation: fade .8s infinite ease-in alternate; } } --Outputs-- .avatar { background-color: red; height: 120px; margin: 40px; width: 120px; } @keyframes fade { 0% { transform: scale(1); } 25% { transform: scale(1.1); } 50% { transform: scale(1); } 75% { transform: scale(1.2); } 100% { transform: scale(1.1); } } .avatar:hover { animation: fade .8s infinite ease-in alternate; }
.error { border: 1px #f00; background-color: #fdd; } .seriousError { @extend .error; border-width: 3px; } /*** Outputs ***/ .error, .seriousError { border: 1px #f00; background-color: #fdd; } .seriousError { border-width: 3px; }
@include mq(ml) { .nav-top {display: none;} }
Allows you to import modules and partials
@import "compass/utilities"; @import "partials/base"; @import "partials/fonts";
.profile-img { float: left; width: 10em; @media screen and (min-width: 25em){ width: 15em; } } --OutPuts-- .profile-img { float: left; width: 10em; } @media screen and (min-width: 25em) { .profile-img { width: 15em; } }
@mixin transform ($scale){ -webkit-transform: scale($scale); -moz-transform: scale($scale); -ms-transform: scale($scale); -o-transform: scale($scale); transform: scale($scale); } .foo {@include transform(.5);}
.foo { -webkit-transform: scale(0.5); -moz-transform: scale(0.5); -ms-transform: scale(0.5); -o-transform: scale(0.5); transform: scale(0.5); }
@function f($a) { @return if(length($a) > 1, nth($a, 2), $a); }
@mixin li ($style) { @if ($style == float) { float:right; margin-left: 2%; } @else if ($style == inline){ display: inline; margin-right: 2%; } }
$breakpoints: ( s: 20em, m: 30em, l: 48em, xl: 64em, ); @mixin mq($) { @each $name, $breakpoint in $breakpoints { @if ($name == $size) { @media (max-width: $breakpoint) { @content; } } } }
@for $i from 1 through $grid-columns { .grid-#{$i} { @include grid-base($i); @extend .grid-block; } }
$types: 4 $type-width: 20px @while $types > 0 .while-#{$types} width: $type-width + $types $types: $types - 1
RGB, HSL, Opacity, Color, String, Number, List, Map, Introspection
@function percent() { @return ($container-width/$col-width) * 100; }
$a: 1 2 3 4 5 a f;
$a: ('city': brooklyn, 'state': new York, );
And many more ...