April 01, 2017
I was a bit confused with so many sass versions. Here is the gist:
Sass was primarily written in ruby language as a gem. Ruby Sass, the original one, works perfectly in a ruby environment. LibSass is the C/C++ converted library of Ruby Sass which removes ruby dependency. Node Sass is the javascript implementation of the LibSass library, there are other implemntations of the library as well. More details…
Use either npm
or yarn
to download node-sass and -D
it.
npm init
to create package.json, if already there then skip this.yarn add node-sass -D
This adds node-sass dependency to package.json
"styles": node-sass -o css scss
Add this to the scripts section, node-sass will output to the css folder by reading the scss folder contents.P.S: Add semicolons where needed in scss files , sometimes you get errors if missing.
SCSS partials files start with _
and can be imported using @import "partial-file"
without the _ and file extension inside other SCSS files. Also order matters while carrying over variables between files.
If partials name does not start with _ , then same files are copied over to the css by node-sass instead of a single master css file.
Nesting in CSS is awesome and it helps keep code DRY. Use &
to refer to parent class and also use it a name extension.
.fruits{
&-tree{
height: 100%;
}
&::before{
display:inline;
}
.apple{
border-radius: 25px;
}
}
&-tree on node-sass creates fruits-tree, nested apple className refers to apple class inside the fruits element, also pseudo selectors before and after refer to the direct parent element.
Variables are awesome, helps changing values a breeze. They can not only hold style values, they can also be interpolated. Variables can also be overwritten and are block scoped.
$apple-color: red;
$garden-name: its-the-eden
.apple{
color: $apple-color;
}
.garden{
content: "#{$garden-name}"
}
#{$garden-name}-area{
display: block;
}
Have a single file to have all variables and import at top for easier maintenance.
SASS provides a lot of inbuilt functions for looping, mapping, lists, strings etc. Few of the color functions
Written by Venkat Ganesan who is in San Francisco now, moving to Toronto. I love building things.Follow me on Twitter