Sass - Tutorial

60
Bringing sassy to CSS. Eric Scott Sembrat | Georgia Institute of Technology | 2013 Theming with Sass

description

Tutorial de SASS Pré processadores com css

Transcript of Sass - Tutorial

Page 1: Sass - Tutorial

Bringing sassy to CSS.

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Theming with Sass

Page 2: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

About MeEric Scott Sembrat • Web Developer at Georgia

Institute of Technology• Graduate Student at Georgia

State University• Lives in Atlanta, Georgia!

Twitter: @esembratWebsite: ericsembrat.com

Page 3: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Game Plan

•Knowing Your Audience•The State of CSS•Introduction to Sass•Features of Sass•Advanced Features•Using Sass•A short and lovely demo

Page 4: Sass - Tutorial

You can test out Sass during this presentation!

Eric Scott Sembrat | Georgia Institute of Technology | 2013

http://sassmeister.com/

Page 5: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Knowing Your Audience

Page 6: Sass - Tutorial

The preprocessor, not the attitude.

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Who has heard of Sass?

Page 7: Sass - Tutorial

It’s super effective!

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Who has used Sass?

Page 8: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

State of CSS

Page 9: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Frustrations with CSS

•CSS has not aged well.•Vendor-specific prefixes in CSS3.•Replacing a color value in a project.•Copying and pasting a style (over and over again).

•These are not features; they’re nightmares!

Page 10: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Page 11: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Page 12: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Fixing CSS

•What if you could give CSS a makeover?•Make it intelligent.•Make it scalable.•Make it re-usable.

Page 13: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Intro to Sass

Page 14: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

History

•Syntactically Awesome Stylesheets•First developed in 2007.

!

•Serves as:•Scripting language.•Preprocessor for CSS.

Page 15: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Function

•Sass compiles into CSS files. !

•Two formatting conventions•.SASS•.SCSS

Page 16: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

.SCSS

•SCSS follows conventions of CSS.

Page 17: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

.SASS

•SASS focuses on indentation and short-hand.

Page 18: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Hard to Choose?

•Sass can convert between SASS and SCSS with relative ease.

Page 19: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Sassy Components

•A Sass project (such as a Drupal theme) only needs two key components:•config.rb•sass/{sass files here}

Page 20: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

config.rb

Page 21: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

config.rb

Almost always auto-generated!

Page 22: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

/sass/

Page 23: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Sassy Features

Page 24: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Features

•Sass has 5 primary features.•Variables•Nesting•Mixins•Partials•Inheritance

Page 25: Sass - Tutorial

Let’s time-travel back to Computer Science 1101.

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Variables

Page 26: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Variables

•Variables allow you to assign a value to an easy-to-remember placeholder name.•Works with hex values, strings of text, colors, numbers, boolean values, or even value lists.

•No more memorizing hex values!

Page 27: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Variables

•Pro-tip: Variables have scope based on where they are defined.

Page 28: Sass - Tutorial

Not the empty-nest variety.

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Nesting

Page 29: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Nesting

•Nested rules allow you to break up endlessly long selectors of CSS.

Page 30: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Nesting

Page 31: Sass - Tutorial

It’s time to cook (up some mixins)!

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Mixins

Page 32: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Mixins

•Mixins allow you to chunk up CSS declarations to be reusable with one reference.

•Pro-tip: Mixins can reference mixins as well.

Page 33: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Mixins

Page 34: Sass - Tutorial

Spring cleaning for CSS.

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Partials

Page 35: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Partials

•CSS Fact of Life:•CSS files can get long (and unwieldy).

•Sass allows you to create partial files to modularize and organize your code.

Page 36: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Visualizing Partials

_header.scss

_sidebar.scss

_page.scss

global.scss global.css

Page 37: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Visualizing Partials

_header.scss

_sidebar.scss

_page.scss

global.scss global.css

Page 38: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Visualizing Partials

_header.scss

_sidebar.scss

_page.scss

global.scss global.css

Sass CSS

Page 39: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Visualizing Partials

_header.scss

_sidebar.scss

_page.scss

global.scss global.css

Sass CSS

compilesinherits

inherits

inherits

Page 40: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Creating Partials

•Creating partials can be done in two steps.

Page 41: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Step 1: Create Partial

•Create a _filename.scss in your SASS folder.

Page 42: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Step 2: Reference Partial

•Reference the partial Sass file in your non-partial Sass file!

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

Page 43: Sass - Tutorial

Copy and paste no more, theme developers! Inheritance is here!

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Inheritance

Page 44: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Inheritance

•Inheritance imports syntax and style from another section of your SASS project.

Page 45: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Inheritance

Page 46: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

More Features

Page 47: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Vendor Prefix Woes

•While Sass has tons of features out of the box, it is missing one key component:•CSS3 vendor-specific prefixes

!

•However, there is a mixin collection that fixes this.•Compass

Page 48: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Compass

•Compass is a Sass framework extension focused on CSS3 and layouts.•http://compass-style.org/reference/compass/•Essentially, a big set of mixins.

Page 49: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Using Compass

•Installing Compass is similar to installing Sass.•http://compass-style.org/install/

Page 50: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Using Sass

Page 51: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

When to Compile Sass

•There are two methods of using Sass on a Drupal website.•Letting Drupal Compile Sass•Compiling Sass locally

Page 52: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Compiling Server Side

•There’s a Drupal module for that!•https://drupal.org/project/sass

•Consider memory load, revisioning, etc.

Page 53: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Compiling Locally

•Most local compilers for Sass require Ruby to be installed.•Two main ways of compiling locally:

•Command Line•GUIs

Page 54: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Local: GUIs

•Quite a few GUIs available:•http://sass-lang.com/install•See: Compass.app & Scout

Page 55: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Local: Command Line

•Installing locally is dependent on your OS. •http://sass-lang.com/install

•Requires Ruby to be installed.

Page 56: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

My Preference?

•Personally, I’m in love with Compass.app.•http://compass.kkbox.com/

•Scout is a very good “getting started” app.•http://mhs.github.io/scout-app/

Page 57: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Demo? Demo!

Page 58: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Want to Learn More?

Page 59: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

More Information

• http://sass-lang.com/guide• http://compass-style.org/reference/compass/• http://thesassway.com/beginner/getting-started-with-sass-and-

compass

Page 60: Sass - Tutorial

Eric Scott Sembrat | Georgia Institute of Technology | 2013

Thanks!