# Sass

  • Sass is a CSS pre-processor, which means that it is processed and generates the CSS before the CSS is sent to the browser.
  • As the designer / developer you will write the Sass commands to generate the CSS.
  • You will compile the Sass code into CSS.
  • The finished CSS is what will be linked to on the webpage, just like always.
  • The official website Sass website (opens new window)
  • There are other CSS pre-processors that you may encounter
  • LESS (opens new window) and Stylus (opens new window) are two popular ones.
  • The popularity of LESS has reduced lately. Sass and Stylus are the two most popular.

# Sass Installation

  • It can be installed in several ways.
  • We will be using the DART version of Sass.
  • About DART Sass (opens new window)
  • Install Instructions (opens new window)
  • We are using the DART version because it has the least issues with installs and running.
  • You can install Sass with Ruby but that requires extra install work for Windows.
  • You can install and run Sass with npm but it runs slower than with DART or RUBY.
  • On Windows you can use Choclatey package manager to install a stand alone version.
  • On OSX or Linux you can use HomeBrew to install a stand alone version.
  • You can run Sass in the browser with JavaScript but this is inefficient and forces the user to download more and do the processing.
  • We will be running it from the CLI with Dart-Sass
  • Go HERE (opens new window) to download the proper version for your Windows x64.
  • You will then need to add it to your PATH Environmental variable. Instructions (opens new window)

# Running Sass

  • For Sass to do the pre-processing we need to set it up.
  • We will have one folder where we save our .scss files
  • Then we run the command to compile the Sass and tell it where to put the newly generated .css file(s)
  • Let's say we have the following project structure
    folder structure
  • Now let's say that there is a file inside the sass folder called main.scss
  • We want to convert that file from Sass to CSS, so on the CLI, from the root folder of our project, we type:
sass sass/main.scss:css/main.css
1
  • That will run the compiler once to convert the Sass file into a file, inside the css folder, called main.css

  • If you wanted to convert ALL the files inside the sass folder into css files of the same name inside the css folder then type:

sass sass/:css/
1

TIP

Use imports in Sass to combine your Sass files into a single CSS file that can be linked to from your HTML

  • If you want to have Sass constantly watch your folder for changes to files as they are saved then you can use the --watch flag.
  • To stop Sass watching your files, use CTRL + C to stop it.
sass --watch sass/:css/
1
  • Finally, there are options for the output style of your CSS.
  • You can output your CSS in an expanded format that makes it easy for you to read.
  • OR
  • You can output your CSS in a compressed format that removes all the comments and extra whitespace so you have a small file-size that is better for sending to the browser.
  • Enter ONE of the lines below
sass --watch sass/:css/ --style expanded
sass --watch sass/:css/ --style compressed
1
2
  • For any of these sass commands there will also be a .css.map file that gets created.
  • The map file will be used to track changes between versions, determine where different parts of the file came from, and to provide debugging information to your IDE.

# Sass Syntax

# Playground for Testing Sass

# To Do Before Week 13

Self-Directed To Do

Last Updated: 10/25/2022, 8:40:26 PM