October 2014 - USG Rock Eagle - Sass 101

51
` 1 PLAYER GAME MARIO 0000000 WORLD 1-1 TIME ROCK_EAGLE Simplifying and extending CSS for the 21st century! 2 PLAYER GAME

description

An introduction to Sass.

Transcript of October 2014 - USG Rock Eagle - Sass 101

Page 1: October 2014 - USG Rock Eagle - Sass 101

`

1 PLAYER GAME

MARIO

0000000

WORLD

1-1

TIME

ROCK_EAGLE

Simplifying and extending CSS for the

21st century!

2 PLAYER GAME

Page 2: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World -1-1

MARIO

0000000

WORLD

-1-1

TIME

ROCK_EAGLE

x 3

Introductionsand

Shout Outs

Page 3: October 2014 - USG Rock Eagle - Sass 101

• Web Manager - College of Engineering, Georgia Tech

• Ph.D. Student - Instructional Technology, Georgia State !!

• Website: http://ericsembrat.com• Twitter: @esembrat

Eric Sembrat

Page 4: October 2014 - USG Rock Eagle - Sass 101

• The State of CSS• Enter: CSS Preprocessors• How Sass Works• Sass Features• Q&A / Discussion

World Map

Page 5: October 2014 - USG Rock Eagle - Sass 101

And now, for some plugs..

Page 6: October 2014 - USG Rock Eagle - Sass 101

• Communication list for web developmentdiscussion between the 31 institutionsin the University System of Georgia.!

• http://usgweb.gatech.edu

USGWeb Collaboration Group

Page 7: October 2014 - USG Rock Eagle - Sass 101

http://atlanta.buildguild.org/

Page 8: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World 1-1

MARIO

0000000

WORLD

1-1

TIME

ROCK_EAGLE

x 3

The State of CSS

Page 9: October 2014 - USG Rock Eagle - Sass 101

We’ve come a long way…

Page 10: October 2014 - USG Rock Eagle - Sass 101

We’ve come a long way…

Page 11: October 2014 - USG Rock Eagle - Sass 101

• Before CSS, there were inline element styles.

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

Page 12: October 2014 - USG Rock Eagle - Sass 101

• Before CSS, there were inline element styles.!

• Then CSS was born with style.

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

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

Page 13: October 2014 - USG Rock Eagle - 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 14: October 2014 - USG Rock Eagle - Sass 101

CSS Has Not Aged Well..Variables

CSS3

Inheritance

Reusability

CSS Organization

Media Queries

Theme Templates

Page 15: October 2014 - USG Rock Eagle - 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 16: October 2014 - USG Rock Eagle - Sass 101

Don’t Repeat Yourself

Page 17: October 2014 - USG Rock Eagle - Sass 101

• Minimizing repetition of the information in a project

• Modifications only happen in one place

!

• Construction of repetitive, reusable, and scalable elements

What is DRY?

Page 18: October 2014 - USG Rock Eagle - Sass 101

• CSS does not have DRY capabilities built-in:

• Variables (i.e. color, font)• Media queries• Chunks of CSS

DRY in CSS

• So, how do we fix CSS and get out of this mess?

Page 19: October 2014 - USG Rock Eagle - Sass 101

Sass to the Rescue!

http://sass-lang.com/

Page 20: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World 2-1

MARIO

0000000

WORLD

2-1

TIME

ROCK_EAGLE

x 3

What is Sass?

Page 21: October 2014 - USG Rock Eagle - 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 22: October 2014 - USG Rock Eagle - 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 23: October 2014 - USG Rock Eagle - 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 24: October 2014 - USG Rock Eagle - Sass 101

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

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

Page 25: October 2014 - USG Rock Eagle - Sass 101

What does Ruby run on?• Sass was originally developed as in the Ruby programming language.

• Sass was recently ported over to C/C++ as LibSass.

Page 26: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World 3-1

MARIO

0000000

WORLD

3-1

TIME

ROCK_EAGLE

x 3

Using Sass

Page 27: October 2014 - USG Rock Eagle - Sass 101

• SassMeister• http://sassmeister.com/

Web Console

Page 28: October 2014 - USG Rock Eagle - 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 29: October 2014 - USG Rock Eagle - Sass 101

Scout

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

Page 30: October 2014 - USG Rock Eagle - Sass 101

CodeKit

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

Page 31: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World 4-1

MARIO

0000000

WORLD

4-1

TIME

ROCK_EAGLE

x 3

Sass Features

Page 32: October 2014 - USG Rock Eagle - Sass 101

• Learn many of the essential features of Sass.

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

2) Learn the Syntax

Page 33: October 2014 - USG Rock Eagle - 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 34: October 2014 - USG Rock Eagle - 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 35: October 2014 - USG Rock Eagle - Sass 101

Mixins

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

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

Page 36: October 2014 - USG Rock Eagle - 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 37: October 2014 - USG Rock Eagle - 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 38: October 2014 - USG Rock Eagle - 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 39: October 2014 - USG Rock Eagle - Sass 101

Partials

compiles

to

_hdr.scss

_ftr.scss

global.scss global.css

Page 40: October 2014 - USG Rock Eagle - 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 41: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World 5-1

MARIO

0000000

WORLD

5-1

TIME

ROCK_EAGLE

x 3

Advanced Features

Page 42: October 2014 - USG Rock Eagle - Sass 101

• Methodology for naming classes.

Block Element Modifier (BEM)

.BLOCK{__ELEMENT[--MODIFIER]}

Page 43: October 2014 - USG Rock Eagle - Sass 101

• Methodology for naming classes.

Block Element Modifier (BEM)

.BLOCK{__ELEMENT[--MODIFIER]}

.COLOR__PRIMARY.COLOR__PRIMARY--LIGHT .COLOR__PRIMARY--DARK

Page 44: October 2014 - USG Rock Eagle - Sass 101

• Can be programmatically built into Sass.

Block Element Modifier (BEM)

Page 45: October 2014 - USG Rock Eagle - Sass 101

• Can be programmatically built into Sass.

Block Element Modifier (BEM)

Page 46: October 2014 - USG Rock Eagle - Sass 101

• Source maps allow you to see the original source (Sass) instead of the compiled CSS while debugging.

Source Maps

Page 47: October 2014 - USG Rock Eagle - Sass 101

• Requires enabling source-maps on Sass and in the desired browser (Chrome & Firefox, Safari).

Source Maps

http://thesassway.com/intermediate/using-source-maps-with-sass

Page 48: October 2014 - USG Rock Eagle - Sass 101

• Associations of “key” | “value” objects.!

!

!

!

• Similar to programming arrays.• map-merge()• map-get()• map-remove()

Maps

$map: (key1: value1, key2: value2, key3: value3);

Page 49: October 2014 - USG Rock Eagle - Sass 101

Section TextBody Level One

World 6-1

MARIO

0000000

WORLD

6-1

TIME

ROCK_EAGLE

x 3

Demo?

Page 50: October 2014 - USG Rock Eagle - Sass 101

DemoQuick highlights and features!

Page 51: October 2014 - USG Rock Eagle - Sass 101

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