35
CSS with superpowers ― SASS! Ferdinand Vogler @ferdinandvogler

CSS with superpowers - SASS!

  • Upload
    fv0

  • View
    270

  • Download
    2

Embed Size (px)

DESCRIPTION

These are my slides from the Meetup "CSS with superpowers - SASS!" at ImmobilienScout24 on November 6, 2014. Description: Preprocessors for CSS have become the industry standard and you'll be reading more and more about them all over the tech community. They're named LESS, Stylus or SASS. Preprocessors make CSS more flexible, maintainable and fill in where CSS has its limits and drawbacks.

Citation preview

Page 1: CSS with superpowers - SASS!

CSS with superpowers ―

SASS!

Ferdinand Vogler@ferdinandvogler

Page 2: CSS with superpowers - SASS!

Ferdinand Vogler@ferdinandvogler

Communication Design student, Working student at YOU IS NOW,

Freelance Designer and Web-Developer

Page 3: CSS with superpowers - SASS!
Page 4: CSS with superpowers - SASS!

OpenTechSchoolopentechschool.org

Berlin, Brussels, Dortmund, Hamburg, Istanbul, Jerusalem, London, Melbourne, Nairobi, Ramallah, RheinMain, Stockholm, San Francisco, Tel-

Aviv, Washington, Zürich

Page 5: CSS with superpowers - SASS!

“If you really want to learn how to do something, try teaching other people how to do it.”

– Steve Krug, Rocket Surgery Made Easy

Page 6: CSS with superpowers - SASS!

Why SASS?

Page 7: CSS with superpowers - SASS!

1996First W3C recommendation (CSS1)

Page 8: CSS with superpowers - SASS!

2014

Page 9: CSS with superpowers - SASS!

Preprocessors

Page 10: CSS with superpowers - SASS!

Advantages

❏ Variables

❏ Nesting

❏ Reusable blocks

❏ Fewer HTTP requests

❏ Conditionals, Loops & Functions

❏ Mathematics

Don’t Repeat Yourself

Page 11: CSS with superpowers - SASS!

How does it work?

style.scss style.cssPreprocessor

Page 12: CSS with superpowers - SASS!

style.css

a { color: gray;}

a:hover { color: black; font-weight: bold;}

p { margin: 10px;}

style.scss

Page 13: CSS with superpowers - SASS!

“Later, when you’ve become fluent with Sass […], it really does feel like a natural extension

of CSS — as if it’s filling holes we all wish were filled by the CSS spec itself.”

Dan Cederholm in alistapart.com/article/why-sass

Page 14: CSS with superpowers - SASS!

ಠ_ಠ

Page 15: CSS with superpowers - SASS!

Nope.

Page 16: CSS with superpowers - SASS!

?SASS?

SCSS?

Page 17: CSS with superpowers - SASS!

style.scss style.sass

@mixin border-radius($radius) { -webkit-border-radius: $radius; -moz-border-radius: $radius; -ms-border-radius: $radius; border-radius: $radius;}

#main { background: gray; width: 50%; @include border-radius(4px);

p { background: lightgray; color: black; }}

=border-radius($radius)––-webkit-border-radius: $radius––-moz-border-radius: $radius––-ms-border-radius: $radius––border-radius: $radius

#main ––background: gray––width: 50%––+border-radius(4px)

––p––––background: lightgray––––color: black

Page 18: CSS with superpowers - SASS!

Install SASS

Page 19: CSS with superpowers - SASS!

Ruby GemsMacOpen Terminal: ruby -v

WindowsInstall from www.rubyinstaller.org

Page 20: CSS with superpowers - SASS!

InstallationMacsudo gem install sass

Windowsgem install sass

Page 21: CSS with superpowers - SASS!

AppsCodeKitPreprosScoutKoalaCompassHammerMixtureLiveReload…

Page 22: CSS with superpowers - SASS!

<>Live-Coding

Basic Terminal usage

Page 23: CSS with superpowers - SASS!

Commandscd Change directory cd .. Go back one directory cd ~ Go to Homels List directory

touch Create filerm Remove filemkdir Make directoryrmdir Remove directory

Page 24: CSS with superpowers - SASS!

<>Live-CodingSASS in the command line

Page 25: CSS with superpowers - SASS!

Basic SASS commandssass input.scss output.css Compile once

sass --watch input.scss:output.css Watch filesass --watch scss:css Watch folder

Page 26: CSS with superpowers - SASS!

Partials

|stylesheets|--style.css

/* Buttons */

/* Panels */

/* Lists */

CSS

Page 27: CSS with superpowers - SASS!

Partials|stylesheets

|--partials

|------_buttons.scss

|------_panels.scss

|------_lists.scss

|--vendor

|----_normalize.scss

|--style.scss

@import “partials/buttons”;

@import “partials/panels”;

@import “partials/lists”;

// Third-party stylesheets

@import “vendor/normalize”;

SCSS

style.css

Page 28: CSS with superpowers - SASS!

<>Live-Coding

SASS playground

Page 29: CSS with superpowers - SASS!

Variables

$color = red;$darkercolor = darken($color, 25%);$lightercolor = lighten($color, 15%);

adjust-hue(); saturate(); mix(); grayscale(); desaturate(); invert(); complement();

Page 30: CSS with superpowers - SASS!

Nesting

.my-style {.highlight {a {&:hover {}

}}

}

Page 31: CSS with superpowers - SASS!

Fewer HTTP requests

|stylesheets

|--partials

|------_buttons.scss

|------_panels.scss

|------_lists.scss

|--vendor

|----_normalize.scss

|--style.scss

style.css

Page 32: CSS with superpowers - SASS!

Conditionals, Loops & Functions

@function sample($var1, $var2) {… }

@for $i from 1 through 10 {… }

@mixin block($var1) {@if $var1 == large {… }

}

Page 33: CSS with superpowers - SASS!

Scratching the surface

Page 34: CSS with superpowers - SASS!

Further information

❏ www.thesassway.com

❏ www.sass-lang.com

❏ www.leveluptuts.com/tutorials/sass-tutorials

❏ Dan Cederholm – “SASS for Web-Designers”

❏ www.sassmeister.com

Page 35: CSS with superpowers - SASS!

Questions? Feedback?@ferdinandvogler