DrupalCamp Chattanooga - September 2014 - Sass 101

35
Sass 101 Cleaning up your CSS Closet (once & for all)! Eric Sembrat - DrupalCamp Chattanooga - September 2014

description

Cleaning up your CSS and Sass closet!

Transcript of DrupalCamp Chattanooga - September 2014 - Sass 101

Page 1: DrupalCamp Chattanooga - September 2014 - Sass 101

Sass 101Cleaning up your CSS Closet (once & for all)!

Eric Sembrat - DrupalCamp Chattanooga - September 2014

Page 2: DrupalCamp Chattanooga - September 2014 - Sass 101

Who Am I?A quick introduction!

Page 3: DrupalCamp Chattanooga - September 2014 - Sass 101

• Web Manager for the College of Engineering at Georgia Tech

• Ph.D. Student in Instructional Technology at Georgia State University !

• Website: http://ericsembrat.com• Twitter: @esembrat• Hashtag: #Sassnooga

Eric Sembrat

Page 4: DrupalCamp Chattanooga - September 2014 - Sass 101

• State of CSS• What is Sass?• How to Use Sass• Demo• Questions / Comments

Our Roadmap

Page 5: DrupalCamp Chattanooga - September 2014 - Sass 101

The State of CSSTime to get serious about how we theme our themes

Page 6: DrupalCamp Chattanooga - September 2014 - Sass 101

We’ve come a long way…

Page 7: DrupalCamp Chattanooga - September 2014 - Sass 101

We’ve come a long way…

Page 8: DrupalCamp Chattanooga - September 2014 - Sass 101

• Before CSS, there were inline element styles.!

• Then CSS was born with style.!

• Finally, CSS grew too big to live with HTML.

CSS Growing Up<font color=“green” size=“8” family=“Wingdings”>

<font style=“color: green; font-size: 8pt; font-family: Wingdings”>

@import url(fancy-pants-css.css);

Page 9: DrupalCamp Chattanooga - September 2014 - Sass 101

CSS Has Not Aged Well..Variables

CSS3

Inheritance

Reusability

Clutter

Media Queries

Theme Templates

Page 10: DrupalCamp Chattanooga - September 2014 - Sass 101

• CSS4 looks to fix some of these issues (1)

• Parent Selectors• Grids

Some of this will change..

• However, there’s still one big elephant in the room.

Page 11: DrupalCamp Chattanooga - September 2014 - Sass 101

Don’t Repeat Yourself (DRY)

The programming mantra of “Don’t Repeat Yourself”

Page 12: DrupalCamp Chattanooga - September 2014 - Sass 101

• Minimizing repeating the same declaration over and over again

• Modifications only happen in one place

!

• Modeled around the construction of repetitive, reusable, and scalable elements

What is DRY?

Page 13: DrupalCamp Chattanooga - September 2014 - Sass 101

• CSS is too lazy to learn to DRY

• Variables like color, font• Media queries• Chunks of CSS

DRY in CSS

• So, how do we fix this mess we are in?

Page 14: DrupalCamp Chattanooga - September 2014 - Sass 101

Sass to the Rescue!

Page 15: DrupalCamp Chattanooga - September 2014 - Sass 101

What is Sass?How Sass cleans out the CSS closet, once and for all!

Page 16: DrupalCamp Chattanooga - September 2014 - Sass 101

• Sass is a preprocessor for CSS• Converts Sass short-code into clunky, ugly CSS• Serves as a translator

Preprocessor

CSS

compiles

to

SASS

Page 17: DrupalCamp Chattanooga - September 2014 - Sass 101

• Sass uses a very CSS-like syntax (.SCSS) to extend new features into the syntax you already know!

• An alternative is a tab-centric syntax (.SASS)

Sass

Page 18: DrupalCamp Chattanooga - September 2014 - Sass 101

Compare

http://thesassway.com/editorial/sass-vs-scss-which-syntax-is-better

#main { color: blue; font-size: 0.3em; }

#main! color: blue font-size: 0.3em

• Our CSS-friendly .SCSS formatting option.

• Or, the tab-centric .SASS formatting option.

Page 19: DrupalCamp Chattanooga - September 2014 - Sass 101

.SCSS vs. .SASS• Changing syntax is an automated process:

• http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax

Page 20: DrupalCamp Chattanooga - September 2014 - Sass 101

Using SassHow Sass cleans out the CSS closet, once and for all!

Page 21: DrupalCamp Chattanooga - September 2014 - Sass 101

• SassMeister• http://sassmeister.com/

0) Test Sass All Day

Page 22: DrupalCamp Chattanooga - September 2014 - Sass 101

• Easiest way to get started is to download a Sass application.

• http://sass-lang.com/install• Multi-platform releases• Free and paid products available

1) Get a App

Page 23: DrupalCamp Chattanooga - September 2014 - Sass 101

Scout

Scout - http://mhs.github.io/scout-app/

Page 24: DrupalCamp Chattanooga - September 2014 - Sass 101

CodeKit

CodeKit - https://incident57.com/codekit/

Page 25: DrupalCamp Chattanooga - September 2014 - Sass 101

• Learn many of the essential features of Sass.

• Variables• Nesting• Mixins• Plugins• Partials• (and more!)

2) Learn the Syntax

Page 26: DrupalCamp Chattanooga - September 2014 - Sass 101

Variables

$pretty-blue: #0000FF; $pretty-font-size: 0.3em; !#main { color: $pretty-blue; font-size: $pretty-font-size; }

#main { color: #0000FF; font-size: 0.3em; }

Page 27: DrupalCamp Chattanooga - September 2014 - Sass 101

Nesting$pretty-blue: #0000FF; !#main { color: $pretty-blue; font-size: 0.3em; #slideshow { background-color: mix(#FFF, $pretty- blue, 20%); } }

#main { color: #0000FF; font-size: 0.3em; } !#main #slideshow { background-color: #3333ff; }

Page 28: DrupalCamp Chattanooga - September 2014 - Sass 101

Mixins

@mixin chattanooga() { background-color: pink; font-size: 25pt; } !#body #chattanooga { @include chattanooga(); }

#body #chattanooga { background-color: pink; font-size: 25pt; }

Page 29: DrupalCamp Chattanooga - September 2014 - Sass 101

Mixins

@mixin chattanooga() { background-color: pink; font-size: 25pt; } !#body #chattanooga { @include chattanooga(); }

#body #chattanooga { background-color: pink; font-size: 25pt; }

Mixins can reference mixins!

Page 30: DrupalCamp Chattanooga - September 2014 - Sass 101

Mixins

@mixin chattanooga() { background-color: pink; font-size: 25pt; } !#body #chattanooga { @include chattanooga(); }

#body #chattanooga { background-color: pink; font-size: 25pt; }

Mixins can take arguments (with default values)!

Page 31: DrupalCamp Chattanooga - September 2014 - Sass 101

Plugins• Compass

• http://compass-style.org/

• Sass Globbing• https://github.com/chriseppstein/sass-globbing

• Breakpoint • http://breakpoint-sass.com/

• Bourbon • http://bourbon.io/

Page 32: DrupalCamp Chattanooga - September 2014 - Sass 101

Partials

compiles

to

_hdr.scss

_ftr.scss

global.scss global.css

Page 33: DrupalCamp Chattanooga - September 2014 - Sass 101

• Sass uses a configuration file (config.rb) to control CSS output

• Requires Compass• http://compass-style.org/help/documentation/configuration-

reference/

Configure CSS Output

Page 34: DrupalCamp Chattanooga - September 2014 - Sass 101

DemoQuick highlights and features!

Page 35: DrupalCamp Chattanooga - September 2014 - Sass 101

Let’s ChatQuestions, Comments, Concerns, Discussions about Sass