Slides available at: bit.ly/CSSCmp
#LadyDevs
#KCWiT
#CodingAndCocktailsKC
Photo by JD Hancock cc
Image Credit:
LearnWebCode.comh1 { ... }
.my-class { ... }
#my-id { ... }
div p { ... }
Taking input (Sass in our case) and converting (or compiling) it into something else (plain old CSS in this case) so it can be understood by a third thing (your browser in this case)
Since your browser is considered to be the processor for your website, Sass is considered a preprocessor because it processes the code before your browser does.No significant technical distinction
Preprocessor Postprocessor Sass, Less PostCSS, Autoprefixer Sometimes Own Syntax CSS Syntax Compiles into CSS Compiles into CSS Allows use of proposed CSS features or features not yet supported add browser prefixes is a common usage for postprocessors$my-color: #fff;
@import "variables";
.container { margin: 0; padding: 0; .item { margin-bottom: 20px; border-top: 2px solid blue; } }
.container { margin: 0; padding: 0; } .container .item { margin-bottom: 20px; border-top: 2px solid blue; }4 or more levels can create bloated, unnecessary CSS
@mixin link-style ($link, $visit, $hover, $active) { a { color: $link; &:visited { color: $visit; } &:hover { color: $hover; } &:active { color: $active; } } }
a { @import link-style(blue, red, darkblue, green); text-decoration: none; }
$my-var*2
$base_string: "Gin"; $add-on-string: "Tonic"; p:before { content: $base-string + " and " + $add-on-string; //Gin and Tonic }
lighten(#c0ffee, 20%)
darken(#decaff, 20%)
rgba(#f00d1e, 0.5)
$type: pina-colada; p { @if $type == bloody-mary { color: red; } @else if $type == pina-colada { color: white; } @else { color: blue; } }
Compiles to:
p { color: white; }
@for, @while, @each
@for $i from 1 through 3 .style-#{$i} width: 10px * $i
Compiles to:
.style-1 { width: 10px; } .style-2 { width: 20px; } .style-3 { width: 30px; }
.btn { padding:5px; border: 1px solid #666; color:#000; text-decoration:none; } .btn-warning { @extend .btn background: red; }
Despite Sass being awesome, organization is still important
stylesheets/ | |-- modules/ # Common modules | |-- _all.scss # Include to get all modules | |-- _utility.scss # Module name | |-- _colors.scss # Etc... |-- partials/ # Partials | |-- _base.sass # imports for all mixins + global project variables | |-- _buttons.scss # buttons | |-- _figures.scss # figures | |-- _grids.scss # grids | |-- _typography.scss # typography | |-- _reset.scss # reset |-- vendor/ # CSS or Sass from other projects | |-- _colorpicker.scss | |-- _jquery.ui.core.scss | ... | `-- main.scss # primary Sass fileSample Structure from The Sass Way