Syntactically Awesme StyleSheets CSS extensin that adds pwer and elegance t the basic language
Sass An extensin t CSS that adds pwer & elegance t the basic language Allws the use f variables Allws the use f nested rules Allws the use f mixins Allws the use f inline imprts and much mre... all with a fully CSS-cmpatible syntax
Mre n Sass Helps keep large stylesheets well-rganized Gets small stylesheets up and running quickly Prvides many useful functins fr manipulating clrs and ther values There are tw syntaxes available fr Sass SCSS (Sassy CSS) - an extensin f the syntax f CSS. Files using this syntax have the.scss extensin Indented syntax (r smetimes just Sass ) - prvides a mre cncise way f writing CSS. Files using this syntax have the.sass extensin
Sass syntax Either syntax can imprt files written in the ther Files can be autmatically cnverted frm ne syntax t the ther using the sass-cnvert cmmand line tl: # Cnvert Sass t SCSS $ sass-cnvert style.sass style.scss # Cnvert SCSS t Sass $ sass-cnvert style.scss style.sass
Pre-Sass Installatin Befre installing Sass, yu need t install Ruby n yur machine Windws: Use Ruby Installer -- http://rubyinstaller.rg It's a single-click installer that will get everything set up fr yu super fast. LINUX/Ubuntu: $ sud apt-get install rubygems $ sud yum install rubygems
Sass Installatin Ruby is already pre-installed n Mac At a terminal r Cmmand Prmpt: Verify Rubygem is installed - $ gem v Install Sass - $ gem install sass OR $ sud gem install sass LINUX: $ sud su -c "gem install sass" Verify Sass installatin $ sass -v
Preprcessing Stylesheets are getting larger, mre cmplex, and harder t maintain This is where a preprcessr can help Sass lets yu use features that dn't exist in CSS yet like variables, nesting, mixins, inheritance and ther nifty gdies that make writing CSS fun again
Using Sass # Run Sass frm the cmmand line $ sass input.scss utput.css # Watch a single file $ sass --watch input.scss:utput.css # Watch entire directry $ sass --watch app/scss:public/stylesheets $sass --watch./
Sublime Text plugin Install Syntax Highlighting fr Sass 1. Cntrl + Shift + P in Sublime Text 2. In the input field type "install p" 3. Chse "Package Cntrl: Install Package" 4. Enter sass then hit ENTER 5. Verify sass installatin: 1. Repeat 1 2 abve, in step 2 type list p 2. Chse Package Cntrl: List Packages. Scrll t find sass
Use wrking example t explre Sass Checkut prvided html applicatin and pen it in Sublime Text Frm the terminal: $ cd PROJECT_PATH/css/ sass --watch./ Nte style.scss This file will be used t generate style.css style.css shuld NEVER be edited. It is a generated file style.scss imprts a partial Mst f ur wrk will be dne in the imprted partial
Partials Partial Sass files cntain snippets f CSS that yu include in yur ther Sass files files This is a great way t mdularize yur CSS and help keep things easier t maintain A partial is simply a Sass file named with a leading underscre The underscre lets Sass knw that the file is nly a partial file and that it shuld nt be generated int a CSS file Sass partials are used with the @imprt directive
Imprt CSS has an imprt ptin that lets yu split yur CSS int smaller, mre maintainable prtins. The nly drawback is that each time yu use @imprt in CSS it creates anther HTTP request. Sass builds n tp f the current CSS @imprt Sass takes the file that yu want t imprt and cmbines it with the file yu're imprting int s yu can serve a single CSS file t the web brwser
Variables Think f variables as a way t stre infrmatin that yu want t reuse thrughut yur stylesheet Yu can stre things like clrs, fnt stacks, r any CSS value yu think yu'll want t reuse Sass uses the $ symbl t make smething a variable $primary-fnt-stack: "gill sans", "verdana", "arial", san-serif;
Mixins Sme things in CSS are a bit tedius t write, especially vendr prefixes that exist A mixin lets yu make grups f CSS declaratins that yu want t reuse thrughut yur site Yu can even pass in values t make yur mixin mre flexible T create a mixin yu use the @mixin directive and give it a name
Inheritance This is ne f the mst useful features f Sass Using @extend lets yu share a set f CSS prperties frm ne selectr t anther It helps keep yur Sass very DRY In ur example we're ging t create a simple series f headers fr h1 t h5
Nesting When writing HTML yu've prbably nticed that it has a clear nested and visual hierarchy CSS, n the ther hand, desn't Sass will let yu nest yur CSS selectrs in a way that fllws the same visual hierarchy f yur HTML.
Practice! Rewrite CSS and Scss cde fr table related selectrs and imprt in style.scss
Operatrs Ding math in yur CSS is very helpful Sass has a handful f standard math peratrs like +, -, *, /, and %. In ur example we're ging t d sme simple math t calculate widths fr a few elements
http://sass-lang.cm Resurces http://leveluptuts.cm/tutrials/sass-tutrials/ http://rubyinstaller.rg