Top Banner
WYNNNETHERLAND COMPASS, SASS, AND THE ENLIGHTENED WEB
116

Compass, Sass, and the Enlightened CSS Developer

Jan 27, 2015

Download

Design

Wynn Netherland

Slides from RefreshOKC
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Compass, Sass, and the Enlightened CSS Developer

WYNNNETHERLAND

COMPASS, SASS, AND THE ENLIGHTENED WEB

Page 2: Compass, Sass, and the Enlightened CSS Developer

whoami

Page 3: Compass, Sass, and the Enlightened CSS Developer

+

Page 4: Compass, Sass, and the Enlightened CSS Developer
Page 5: Compass, Sass, and the Enlightened CSS Developer

Native Oklahoman

Naturalized Texan

or “Okie” in the local vernacular.

Page 6: Compass, Sass, and the Enlightened CSS Developer

Like you, I work on the Interwebs.

Page 7: Compass, Sass, and the Enlightened CSS Developer

... but my story begins in

Page 8: Compass, Sass, and the Enlightened CSS Developer

theDARK AGES

Page 9: Compass, Sass, and the Enlightened CSS Developer

Literally.

this still works :brew install lynx

Page 10: Compass, Sass, and the Enlightened CSS Developer

gopher:// look it up, kids.

anyone?

Page 11: Compass, Sass, and the Enlightened CSS Developer

Flight of the Navigator

technology from the future!

Page 12: Compass, Sass, and the Enlightened CSS Developer

These were perilous times.

Page 13: Compass, Sass, and the Enlightened CSS Developer

Full of strange magic.

Page 14: Compass, Sass, and the Enlightened CSS Developer

<font>

Page 15: Compass, Sass, and the Enlightened CSS Developer

<center>

Page 16: Compass, Sass, and the Enlightened CSS Developer

<blink>

Page 17: Compass, Sass, and the Enlightened CSS Developer

<table> <tr> <td valign=top>Remember this?</td> <td> <table> <tr> <td>And this?</td> </tr> </table> </td> </tr> </tr></table> Nested tables FTW.

Page 18: Compass, Sass, and the Enlightened CSS Developer

JavaScript vs. JScript

Page 19: Compass, Sass, and the Enlightened CSS Developer
Page 20: Compass, Sass, and the Enlightened CSS Developer

Sometimes we’d hide these andupdate the page without a refresh, backwhen Ajax was something Momma used toclean the bathtub.

Page 21: Compass, Sass, and the Enlightened CSS Developer

DOM level 0.

Page 22: Compass, Sass, and the Enlightened CSS Developer

document.formName.inputName

Page 23: Compass, Sass, and the Enlightened CSS Developer
Page 24: Compass, Sass, and the Enlightened CSS Developer

Why am I sharing all this?

Page 25: Compass, Sass, and the Enlightened CSS Developer

Consider it inoculation against

CURMUDGEONRY.

Page 26: Compass, Sass, and the Enlightened CSS Developer

THAT’S THEWAY IT WAS AND

WE LIKED IT.

Page 27: Compass, Sass, and the Enlightened CSS Developer

“GET OFF MY LAWN.”

Nathan SmithCreator, 960.gsRefreshOKC headlinerReformed Curmudgeon

Page 28: Compass, Sass, and the Enlightened CSS Developer

Back to our story

Page 29: Compass, Sass, and the Enlightened CSS Developer

theRENAISSANCE

Page 30: Compass, Sass, and the Enlightened CSS Developer

JavaScript Frameworks

Page 31: Compass, Sass, and the Enlightened CSS Developer

CSS Frameworks

Page 32: Compass, Sass, and the Enlightened CSS Developer

HTML5

Page 33: Compass, Sass, and the Enlightened CSS Developer

CSS3

Page 34: Compass, Sass, and the Enlightened CSS Developer

border-radius

Page 35: Compass, Sass, and the Enlightened CSS Developer

border-image

Page 37: Compass, Sass, and the Enlightened CSS Developer

background-size

Page 38: Compass, Sass, and the Enlightened CSS Developer

gradients

Page 39: Compass, Sass, and the Enlightened CSS Developer

RGBA, HSL, HSLA colors

rgba (0,0,0,1) is the new black!

Page 40: Compass, Sass, and the Enlightened CSS Developer

text-shadow

Page 41: Compass, Sass, and the Enlightened CSS Developer

box-shadow

Page 42: Compass, Sass, and the Enlightened CSS Developer

wordwrap

Page 43: Compass, Sass, and the Enlightened CSS Developer

outline

Page 44: Compass, Sass, and the Enlightened CSS Developer

columns

Page 45: Compass, Sass, and the Enlightened CSS Developer

@font-face

Typographic freedom!

means

Page 46: Compass, Sass, and the Enlightened CSS Developer

New selectorsCool

Page 47: Compass, Sass, and the Enlightened CSS Developer

* E

.class #id E F

E > F E + F

E[attribute] E[attribute=value] E[attribute~=value] E[attribute|=value]

:first-child :link

:visited :lang() :before ::before :after ::after

:first-letter

::first-letter :first-line ::first-line

E[attribute^=value] E[attribute$=value] E[attribute*=value]

E ~ F :root

:last-child :only-child :nth-child()

:nth-last-child() :first-of-type :last-of-type :only-of-type :nth-of-type()

:nth-last-of-type() :empty :not() :target

:enabled :disabled :checked

CSS3 selectors (and some golden oldies)

:header

Steal this from jQuery, please

Page 48: Compass, Sass, and the Enlightened CSS Developer

This is not a talk about CSS

Follow @smashingmag for your CSS tips & tricks

Page 49: Compass, Sass, and the Enlightened CSS Developer

REAL stylesheet innovationI want to talk about

Page 50: Compass, Sass, and the Enlightened CSS Developer

HOW we write stylesheetsI want to talk about

Page 51: Compass, Sass, and the Enlightened CSS Developer

how we MAINTAIN stylesheetsI want to talk about

Page 52: Compass, Sass, and the Enlightened CSS Developer

how we SIMPLIFY stylesheetsI want to talk about

Page 53: Compass, Sass, and the Enlightened CSS Developer

We're gonna see a brave new world where they run everybody a wire and hook us all up to a grid. Yes, sir, a veritable age of reason. Like the one they had in France. Not a moment too soon.

~ Ulysses Everett McGill

Page 54: Compass, Sass, and the Enlightened CSS Developer

theAGE OF ENLIGHTENMENT

Page 55: Compass, Sass, and the Enlightened CSS Developer

Sass

Page 56: Compass, Sass, and the Enlightened CSS Developer

Syntax options

Page 57: Compass, Sass, and the Enlightened CSS Developer

table.users { tr { td { background: #d1d1d; a { color: #111; } } }}

Syntax options - SCSS Sassy CSS!

Page 58: Compass, Sass, and the Enlightened CSS Developer

table.users tr td background: #d1d1d a color: #111

Syntax options - Indented I ♥ whitespace

Page 59: Compass, Sass, and the Enlightened CSS Developer

Nested rules

Page 60: Compass, Sass, and the Enlightened CSS Developer

table.users tr td a {color: #111}

table.users tr.alt td a {color: #333}

Nested rules - selectors

Page 61: Compass, Sass, and the Enlightened CSS Developer

table.users tr td a color: #111 td.alt a color: #333

Nested rules - selectorsLook, Ma,no braces

or semicolons

But you can useboth if you wanna

Page 62: Compass, Sass, and the Enlightened CSS Developer

table.users tr td color: #111 &.alt color: #333 &:hover color: #666

Nested rules - selectors

Change this

... and you change these

Page 63: Compass, Sass, and the Enlightened CSS Developer

.users font: size: 1.2em style: italics weight: bold

Nested rules - properties

Page 64: Compass, Sass, and the Enlightened CSS Developer

Variables

Page 65: Compass, Sass, and the Enlightened CSS Developer

.user { background: #333; border-size: 2px;}

.owner { background: #333; border-size: 2px;}

.admin { background: #666; border-size: 4px;}

Variables

Page 66: Compass, Sass, and the Enlightened CSS Developer

!gray = #333!default_border = 2px

.user background: = !gray border-size: = !default_border

.owner background: = !gray border-size: = !default_border

.admin background: = !gray + #333 border-size: = !default_border + 2px

Variables

Even math!and color mixing!

Page 67: Compass, Sass, and the Enlightened CSS Developer

Variables$font-apres: Apres, Arial, sans-serif$dark-gray: #1e1e1e !default$body-text: #bbb !default$strong-text: lighten($body-text, 40%)$muted-text: darken($body-text, 40%)$content-background: #fff$content-text: #555$content-border: #ccc$form-background: rgba(0, 0, 0, .5)

$blue-primary: #6095c2$blue-secondary: #1742db$green-primary: #64b900$green-secondary: #298527$pink-primary: #f44ab7

Page 68: Compass, Sass, and the Enlightened CSS Developer

Mixins

Page 69: Compass, Sass, and the Enlightened CSS Developer

.avatar { padding: 2px; border: solid 1px #ddd; position: absolute; top: 5px; left: 5px;}

p img { padding: 2px; border: solid 1px #ddd;}

Mixins

Page 70: Compass, Sass, and the Enlightened CSS Developer

=frame(!padding_width = 2px, !border_color = #ddd) padding = !padding_width border: width: 1px style: solid color = !border_color

.avatar +frame position: absolute top: 5px left: 5px

p img +frame(1px, #ccc)

Mixins

defines the mixin

mixes in the rules

Page 71: Compass, Sass, and the Enlightened CSS Developer

Selector inheritance

Page 72: Compass, Sass, and the Enlightened CSS Developer

.flash { padding: 5px; border-width: 1px; font-weight: bold;}.error { color: #8a1f11; background: #fbe3e4;}.notice { color: #514721; background: #fff6bf;}

Selector inheritance

Page 73: Compass, Sass, and the Enlightened CSS Developer

.flash padding: 5px border-width: 1px font-weight: bold

.error.flash color: #8a1f11 background: #fbe3e4

.notice.flash color: #514721 background: #fff6bf

Selector inheritance

Page 74: Compass, Sass, and the Enlightened CSS Developer

.flash,

.error,

.notice { padding: 5px; border-width: 1px; font-weight: bold; }

.error { color: #8a1f11; background: #fbe3e4; }

.notice { color: #514721; background: #fff6bf; }

Selector inheritance

now we can use a single class in our markup

Page 75: Compass, Sass, and the Enlightened CSS Developer

Imports

Page 76: Compass, Sass, and the Enlightened CSS Developer

@import url(/css/reset.css)@import url(/css/typography.css)@import url(/css/layout.css)

Imports

parent + 3 @imports = 4 http requests

Page 77: Compass, Sass, and the Enlightened CSS Developer

@import reset.sass # _reset.sass@import typography.sass # _typography.sass@import layout.sass # _layout.sass

Imports

Included at compile time - just one http request

Page 78: Compass, Sass, and the Enlightened CSS Developer

Imports + Mixins

Now it gets fun!

Page 79: Compass, Sass, and the Enlightened CSS Developer

@import compass/css3.sass

.callout +border-radius(5px) +linear-gradient("left top", "left bottom", #fff, #ddd)

.callout { -moz-border-radius: 5px; -webkit-border-radius: 5px; -border-radius: 5px; background-image: -moz-linear-gradient(top, bottom, from(#fff), to(#ddd)); background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.00, #fff), color-stop(1.00, #ddd));}

Compass CSS3 mixins

very different syntax

Page 80: Compass, Sass, and the Enlightened CSS Developer

css3/border_radius.sasscss3/inline_block.sasscss3/opacity.sasscss3/text_shadow.sasscss3/box_shadow.sasscss3/columns.sasscss3/box_sizing.sasscss3/gradient.sasscss3/background_clip.sasscss3/background_origin.sasscss3/background_size.sasscss3/font_face.sasscss3/transform.sasscss3/transition.sass

Compass CSS3 mixins

Page 81: Compass, Sass, and the Enlightened CSS Developer

Bring your favorite CSS Framework

Page 82: Compass, Sass, and the Enlightened CSS Developer

<div id='wrapper' class="container"> <div id='content' class="span-7 prepend-1"> <div id='main' class="container"> ... </div> <div id='featured' class="span-5 last"> ... </div> </div> <div id='sidebar' class="span-3 append-1 last"> ... </div></div>

A Blueprint example

boo

Page 83: Compass, Sass, and the Enlightened CSS Developer

@import blueprint/reset.sass@import partials/base.sass@import blueprint@import blueprint/modules/scaffolding.sass

#wrapper +container #content +column(7) +append(1) #featured +column(5, true) #sidebar +column(3, true) +prepend(1)

A Blueprint example

Page 84: Compass, Sass, and the Enlightened CSS Developer

Functions

Page 85: Compass, Sass, and the Enlightened CSS Developer

Very. Powerful. Functions.

Page 86: Compass, Sass, and the Enlightened CSS Developer

hue(#cc3) => 60degsaturation(#cc3) => 60%lightness(#cc3) => 50%

adjust-hue(#cc3, 20deg) => #9c3saturate(#cc3, 10%) => #d9d926desaturate(#cc3, 10%) => #bfbf40lighten(#cc3, 10%) => #d6d65cdarken(#cc3, 10%) => #a3a329

grayscale(#cc3) => desaturate(#cc3, 100%) = #808080complement(#cc3) => adjust-hue(#cc3, 180deg) = #33c

mix(#cc3, #00f) => #e56619mix(#cc3, #00f, 10%) => #f91405mix(#cc3, #00f, 90%) => #d1b72d

Sass 2.4 color functions

http://nex-3.com/posts/89-powerful-color-manipulation-with-sass

Page 87: Compass, Sass, and the Enlightened CSS Developer

mix(rgba(51, 255, 51, 0.75), #f00) => rgba(178, 95, 19, 0.875)mix(rgba(51, 255, 51, 0.90), #f00) => rgba(163, 114, 22, 0.95)

alpha(rgba(51, 255, 51, 0.75)) => 0.75opacity(rgba(51, 255, 51, 0.75)) => 0.75

opacify(rgba(51, 255, 51, 0.75), 0.1) => rgba(51, 255, 51, 0.85)fade-in(rgba(51, 255, 51, 0.75), 0.1) => rgba(51, 255, 51, 0.85)

transparentize(rgba(51, 255, 51, 0.75), 0.1) => rgba(51, 255, 51, 0.65)fade-out(rgba(51, 255, 51, 0.75), 0.1) => rgba(51, 255, 51, 0.65)

Sass 2.4 color functions with alpha support!

http://nex-3.com/posts/89-powerful-color-manipulation-with-sass

Page 88: Compass, Sass, and the Enlightened CSS Developer

Who makes this syntactic sugar?

Page 89: Compass, Sass, and the Enlightened CSS Developer

Sass and CompassCSS extensions &

compilerPatterns &plugins

Page 90: Compass, Sass, and the Enlightened CSS Developer

...like peas and carrots.

Page 91: Compass, Sass, and the Enlightened CSS Developer

$ sudo gem install haml$ sudo gem install compass --pre

CALL IT FROM THE COMMAND LINE$ sass screen.sass screen.css

OR COMPASS-IZE YOUR PROJECT$ compass --rails -f blueprint

OR WATCH A FOLDER$ compass --watch

Sass and Compass

Page 92: Compass, Sass, and the Enlightened CSS Developer

A quick survey of Compass

Page 93: Compass, Sass, and the Enlightened CSS Developer

Blueprint

Page 94: Compass, Sass, and the Enlightened CSS Developer

Blueprint★ Buttons

★ Colors

★ Debug

★ Fancy Type

★ Form

★ Grid

★ Interaction

★ Internet Explorer

★ Link Icons

★ Liquid

★ Print

★ Reset

★ Rtl

★ Scaffolding

★ Typography

★ Utilities

Page 95: Compass, Sass, and the Enlightened CSS Developer

CSS3

Page 96: Compass, Sass, and the Enlightened CSS Developer

CSS3★ Appearance

★ Background Clip

★ Background Origin

★ Background Size

★ Border Radius

★ Box

★ Box Shadow

★ Box Sizing

★ CSS3 Pie

★ Columns

★ Font Face

★ Gradient

★ Images

★ Inline Block

★ Opacity

★ Shared Utilities

★ Text Shadow

★ Transform

★ Transform (legacy)

★ Transition

Page 97: Compass, Sass, and the Enlightened CSS Developer

Image sprites

Page 98: Compass, Sass, and the Enlightened CSS Developer

@import "icon/*.png"

.actions .new +icon-sprite(new) .edit +icon-sprite(edit) .save +icon-sprite(save) .delete +icon-sprite(delete)

Image sprites

.icon-sprite,

.actions .new,

.actions .edit,

.actions .save,

.actions .delete { background: url('/images/icon-34fe0604ab.png') no-repeat; }

.actions .new { background-position: 0 -64px; }

.actions .edit { background-position: 0 -32px; }

.actions .save { background-position: 0 -96px; }

.actions .delete { background-position: 0 0; }

@import "icon/*.png"

public/images/icon/new.pngpublic/images/icon/edit.pngpublic/images/icon/save.pngpublic/images/icon/delete.png

1.2.

3.

I like the Sprite in you®

Page 99: Compass, Sass, and the Enlightened CSS Developer

URL helpers

Page 100: Compass, Sass, and the Enlightened CSS Developer

#nav background: image-url("nav_bg.png") repeat-x top center

DEVELOPMENT#nav { background: url("/images/nav_bg.png") repeat-x top center;}

PRODUCTION#nav { background: url("http://assets.example.com/images/nav_bg.png") repeat-x top center;}

URL helpers

relative paths for development,

absolute for production

Page 101: Compass, Sass, and the Enlightened CSS Developer

stylesheet-url($path)

font-url($path)

image-url($path)

URL helpers

Page 102: Compass, Sass, and the Enlightened CSS Developer

Share your patterns

Page 104: Compass, Sass, and the Enlightened CSS Developer

@import "fancy-buttons"button,a.button +fancy-button(#2966a8)

Page 106: Compass, Sass, and the Enlightened CSS Developer

$ninesixty-columns: 16

#wrap +grid-container #left-nav +alpha +grid(5) #main-content +grid-prefix(1) +grid(10) +omega

Compass 960

https://github.com/chriseppstein/compass-960-plugin

Page 107: Compass, Sass, and the Enlightened CSS Developer

compass-wordpress

Page 108: Compass, Sass, and the Enlightened CSS Developer

$ gem install compass-wordpress

CRANK OUT A NEW SASS-Y WORDPRESS THEME$ compass -r compass-wordpress \ -f wordpress  -p thematic \ --sass-dir=sass --css-dir=css \ -s compressed my_awesome_theme

AUTOCOMPILE YOUR CHANGES$ compass --watch

Compass and WordPress shameless plug

Page 109: Compass, Sass, and the Enlightened CSS Developer

compass-formalize

Announcing!

Page 111: Compass, Sass, and the Enlightened CSS Developer

INSTALL THE GEM$ gem install compass_formalize

CREATE THE COMPASS PROJECT$ compass create my-great-app -r compass_formalize

$ cd my-great-app

APPLY THE PATTERN$ compass install formalize/jquery

Compass and Formalize

Page 112: Compass, Sass, and the Enlightened CSS Developer

Stats

Page 113: Compass, Sass, and the Enlightened CSS Developer

Stats| --------------------------------- | ----- | ---------- | -------------- | ----------- | --------- | -------------- || Filename | Rules | Properties | Mixins Defs | Mixins Used | CSS Rules | CSS Properties || --------------------------------- | ----- | ---------- | -------------- | ----------- | --------- | -------------- || app/stylesheets/_960.sass | 198 | 141 | 0 | 0 | -- | -- || app/stylesheets/_animation.sass | 2 | 2 | 0 | 0 | -- | -- || app/stylesheets/application.sass | 268 | 607 | 0 | 33 | 1131 | 3684 || app/stylesheets/_data_table.sass | 39 | 66 | 0 | 4 | -- | -- || app/stylesheets/_datepicker.sass | 125 | 242 | 0 | 0 | -- | -- || app/stylesheets/_formalize.sass | 82 | 78 | 0 | 4 | -- | -- || app/stylesheets/_forms.sass | 227 | 242 | 0 | 21 | -- | -- || app/stylesheets/ie.sass | 0 | 0 | 0 | 0 | 0 | 0 || app/stylesheets/_jscrollpane.sass | 20 | 43 | 0 | 0 | -- | -- || app/stylesheets/_prettify.sass | 16 | 16 | 0 | 0 | -- | -- || app/stylesheets/print.sass | 0 | 0 | 0 | 0 | 0 | 0 || app/stylesheets/_reset.sass | 111 | 18 | 0 | 0 | -- | -- || app/stylesheets/_text.sass | 27 | 18 | 0 | 0 | -- | -- || app/stylesheets/_tiptip.sass | 19 | 40 | 0 | 0 | -- | -- || app/stylesheets/_util.sass | 56 | 54 | 0 | 0 | -- | -- || app/stylesheets/_vars.sass | 0 | 6 | 2 | 0 | -- | -- || --------------------------------- | ----- | ---------- | -------------- | ----------- | --------- | -------------- || Total (16 files): | 1190 | 1573 | 2 | 62 | 1131 | 3684 || --------------------------------- | ----- | ---------- | -------------- | ----------- | --------- | -------------- |