Transcript
Page 1: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Sassive AggressiveUsing Sass to make your life easier

Page 2: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Who?

Adam DarowskiWeb Developer, PatientsLikeMe

Joel OliveiraDeveloper, The47th

Page 3: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

What is Sass?

Page 4: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

What is Sass?

sass-lang.com

Page 5: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

What is Sass?

•CSS on steroids

•Adds Variables, Mixins, Nesting, Inheritance, and more…

•It’s a meta-language that compiles to plain old CSS

•Two “flavors” - Sass & SCSS

Page 6: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

<rant>

Page 7: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Sass came first

body  background-color: #fff color: #000 font: 16px/1.6 Georgia margin: 0

Page 8: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

SCSS came next

body {  background-color: #fff; color: #000; font: 16px/1.6 Georgia; margin: 0;}

Page 9: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

body#home.home { .content { #learn-more { #faq { margin-top: 20px; aside { width: 300px; padding: 0 40px; h4 span { @include sans-serif-font(20px); } ul { color: #666; font-size: 12px; line-height: 1.5; list-style: square; padding-left: 1.2em; li { margin-bottom: 8px; { li:before { color: red; } } } ol { @include sans-serif-font(24px, $heading-color); list-style: decimal; max-width: 480px; p { font-size: 16px; margin: 1em 0; } } } } }}

Page 10: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

ol { @include sans-serif-font(24px, $heading-color); list-style: decimal; max-width: 480px; p { font-size: 16px; margin: 1em 0; } } } } }}

Page 11: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

body#home.home { .content { #learn-more { #faq { margin-top: 20px; aside { width: 300px; padding: 0 40px; h4 span { @include sans-serif-font(20px); } ul { color: #666; font-size: 12px; line-height: 1.5; list-style: square; padding-left: 1.2em; li { margin-bottom: 8px; { li:before { color: red; } } } ol { @include sans-serif-font(24px, $heading-color); list-style: decimal; max-width: 480px; p { font-size: 16px; margin: 1em 0; } } } } }}

Page 12: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

body#home.home { .content { #learn-more { #faq { margin-top: 20px; aside { width: 300px; padding: 0 40px; h4 span { @include sans-serif-font(20px); } ul { color: #666; font-size: 12px; line-height: 1.5; list-style: square; padding-left: 1.2em; li { margin-bottom: 8px; { li:before { color: red; } } } ol { @include sans-serif-font(24px, $heading-color); list-style: decimal; max-width: 480px; p { font-size: 16px; margin: 1em 0; } } } } }}

body#home.home .content #learn-more #faq margin-top: 20px aside width: 300px padding: 0 40px h4 span @include sans-serif-font(20px) ul color: #666 font-size: 12px line-height: 1.5 list-style: square padding-left: 1.2em li margin-bottom: 8px li:before color: red ol @include sans-serif-font(24px, $heading-color) list-style: decimal max-width: 480px p font-size: 16px margin: 1em 0

Sass > SCSS

Page 13: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

</rant>

Page 14: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Let’s talk about:

1.Nesting2.Mix-ins3.Organization and Refactoring4.Math5.Wrapping Up

Page 15: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Nesting

Page 16: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 17: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 18: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 19: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 20: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Mix-ins

Page 21: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.foo {  -moz-border-radius: 10px;  -webkit-border-radius: 10px;  border-radius: 10px;}

Page 22: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.foo {  property: value;  property: value;  property: value;  -moz-border-radius: 10px;  -webkit-border-radius: 10px;  border-radius: 10px;}

.bar {  property: value;  -moz-border-radius: 10px;  -webkit-border-radius: 10px;  border-radius: 10px;}

.dude {  property: value;  property: value;  -moz-border-radius: 10px;  -webkit-border-radius: 10px;  border-radius: 10px;}

.guy {  property: value;  -moz-border-radius: 10px;  -webkit-border-radius: 10px;  border-radius: 10px;}

Page 23: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

When using Sass…

.foo  +border_radius(10px)

.foo {  -moz-border-radius: 10px;  -webkit-border-radius: 10px;  border-radius: 10px;}

Will render as:

Page 24: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

@mixin border_radius($radius)  -moz-border-radius: $radius  -webkit-border-radius: $radius  border-radius: $radius

The mixin:

Page 25: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.foo  +box_shadow(0, 0, 5px, #AAA)

.foo {  -moz-box-shadow: 0 0 5px #AAA;  -webkit-box-shadow: 0 0 5px #AAA;  box-shadow: 0 0 5px #AAA;}

Another example:

Will render as:

Page 26: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

@mixin box_shadow($h_offset: 0, $v_offset: 0, -->$blur_radius: 5px, $color: #AAA)  -moz-box-shadow: $h_offset $v_offset $blur_radius $color  -webkit-box-shadow: $h_offset $v_offset $blur_radius $color  box-shadow: $h_offset $v_offset $blur_radius $color

Or, pre-populate the mixin:

--> Denotes “not a real line break”

Page 27: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.foo  +box_shadow

.foo {  -moz-box-shadow: 0 0 5px #AAA;  -webkit-box-shadow: 0 0 5px #AAA;  box-shadow: 0 0 5px #AAA;}

Now, no argument is needed:

Will render as:

Page 28: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Or, you can override:

.foo  +box_shadow(2, 2, 10, #CCC)

.foo {  -moz-box-shadow: 2px 2px 10px #CCC;  -webkit-box-shadow: 2px 2px 10px #CCC;  box-shadow: 2px 2px 10px #CCC;}

Will render as:

Page 29: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.foo  +box_gradient(#FFFFFF, #000000)

.foo {  background-image: -moz-linear-gradient(top, #FFFFFF, -->#000000) background-image: -o-linear-gradient(top, #FFFFFF, -->#000000);  background-image: -webkit-gradient(linear,left top,left --> bottom,color-stop(0, #FFFFFF),color-stop(1, #000000))  background-image: -webkit-linear-gradient(#FFFFFF, -->#000000)  background-image: linear-gradient(top, #FFFFFF, #000000)  filter: progid:DXImageTransform.Microsoft.gradient -->(startColorStr='#FFFFFF', EndColorStr='#000000')}

Gradients!

--> Denotes “not a real line break”

Will render as:

http://css3please.com/

Page 30: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

@mixin box_gradient($start,$end)  background-image: -moz-linear-gradient(top, !start, !end) background-image: -o-linear-gradient(top, !start, !end);  background-image: -webkit-gradient(linear,left top,left --> bottom,color-stop(0, !start),color-stop(1, !end))  background-image: -webkit-linear-gradient(!start, !end)  background-image: linear-gradient(top, !start, !end)  filter: progid:DXImageTransform.Microsoft.gradient -->(startColorStr='!start', EndColorStr='!end')

The mixin:

--> Denotes “not a real line break”

Page 32: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.dropdown-inner {  -moz-border-radius: 0 3px 3px 3px;  -webkit-border-radius: 0 3px 3px 3px;  border-radius: 0 3px 3px 3px;  -moz-box-shadow: 1px 1px 4px #CCC;  -webkit-box-shadow: 1px 1px 4px #CCC;  box-shadow: 1px 1px 4px #CCC;  background-image: -moz-linear-gradient(top, #FFFFFF, -->#FCF5DE) background-image: -o-linear-gradient(top, #FFFFFF, -->#000000);  background-image: -webkit-gradient(linear,left top,left --> bottom,color-stop(0, #FFFFFF),color-stop(1, #FCF5DE))  background-image: -webkit-linear-gradient(#FFFFFF, -->#FCF5DE)  background-image: linear-gradient(top, #FFFFFF, #FCF5DE)  filter: progid:DXImageTransform.Microsoft.gradient -->(startColorStr='#FFFFFF', EndColorStr='#FCF5DE')}

Page 33: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.dropdown-inner {  -moz-border-radius: 0 3px 3px 3px;  -webkit-border-radius: 0 3px 3px 3px;  border-radius: 0 3px 3px 3px;  -moz-box-shadow: 1px 1px 4px #CCC;  -webkit-box-shadow: 1px 1px 4px #CCC;  box-shadow: 1px 1px 4px #CCC;  background-image: -moz-linear-gradient(top, #FFFFFF, -->#FCF5DE) background-image: -o-linear-gradient(top, #FFFFFF, -->#000000);  background-image: -webkit-gradient(linear,left top,left --> bottom,color-stop(0, #FFFFFF),color-stop(1, #FCF5DE))  background-image: -webkit-linear-gradient(#FFFFFF, -->#FCF5DE)  background-image: linear-gradient(top, #FFFFFF, #FCF5DE)  filter: progid:DXImageTransform.Microsoft.gradient -->(startColorStr='#FFFFFF', EndColorStr='#FCF5DE')}

.dropdown-inner  +border_radius(0 3px 3px 3px)  +box_shadow(1, 1, 4, #CCC) +box_gradient(#FFFFFF, #FCF5DE)

Page 34: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

• Re-usable interface elements (buttons, headers—with or without arguments).

• Reset styles (data tables, lists, etc.).

• References to frequently-accessed sprites.

• Frequently used IE hacks.

• Etc.

More with mixins:

Page 35: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Organization & Refactoring

Page 36: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 37: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 38: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 39: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 40: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 41: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 42: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 43: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 44: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 45: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 46: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

“.Class Soup”

Page 47: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 48: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 49: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)
Page 50: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Math

Page 51: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.faded  background-color: fade_out(#000, 0.4)

.faded {  background-color: rgba(0, 0, 0, 0.6);}

Color Manipulation:

Will render as:

Page 52: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.lighter  background-color: lighten(#000064, 30%)

.lighter {  background-color: #4B4BFF;}

lighten & darken:

Will render as:

Page 53: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.comp  background-color: complement(#000064)

.comp {  background-color: #646400;}

complement

Will render as:

Page 54: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

$default_color: #000064.level1 background-color: $default_color.level2 background-color: lighten($default_color, 15%).level3 background-color: lighten($default_color, 30%).level4 background-color: lighten($default_color, 45%).level5 background-color: lighten($default_color, 60%)

With a variable:

Page 55: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

.level1 { background-color: #000064; }.level2 { background-color: #0000b1; }.level3 { background-color: #0000fd; }.level4 { background-color: #4b4bff; }.level5 { background-color: #9797ff; }

With a variable:

Page 56: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

$container_width: 1000px$photo_width: 480px.caption width: $container_width - $photo_width

.caption { width: 520px;}

Simple math:

Will render as:

Page 58: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

<ul id="timeline-in"> <li id="dwhite" class="3b level5">White</li> <li id="canson" class="1b hof level2">Anson</li> <li id="jorourke" class="hof lf level4">O'Rourke</li> <li id="pgalvin" class="p hof level2">Galvin</li> <li id="mward" class="hof ss level5">Ward</li> <li id="jmccormick" class="p level3">McCormick</li> <li id="kkelly" class="hof rf level5">Kelly</li> <li id="ggore" class="cf level5">Gore</li> <li id="jglasscock" class="ss level4">Glasscock</li> ... <li id="jbagwell" class="1b level2"></li></ul>

Page 59: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

ul list-style: none padding: 40px 0 0 margin: 0li cursor: pointer margin: 0 0 5px padding: 0 display: block padding: 2px color: white position: relative

Page 60: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

We needmargin-leftand width.

Page 61: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

@mixin bar($start,$end) $start_value: $start - 1870 margin-left: ($start_value*8) + px $length: $end - $start width: ($length*8) - 4px

The mixin:

Page 62: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Pass in arguments for start and end

year.

The mixin:

@mixin bar($start,$end) $start_value: $start - 1870 margin-left: ($start_value*8) + px $length: $end - $start width: ($length*8) - 4px

Page 63: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

$start_value is the difference between the

start year and 1870.

The mixin:

@mixin bar($start,$end) $start_value: $start - 1870 margin-left: ($start_value*8) + px $length: $end - $start width: ($length*8) - 4px

Page 64: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Multiply $start_value by 8 to get the left margin (8 pixels

per year).

The mixin:

@mixin bar($start,$end) $start_value: $start - 1870 margin-left: ($start_value*8) + px $length: $end - $start width: ($length*8) - 4px

Page 65: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Career $length will be used to determine the width of the

box.

The mixin:

@mixin bar($start,$end) $start_value: $start - 1870 margin-left: ($start_value*8) + px $length: $end - $start width: ($length*8) - 4px

Page 66: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Again, multiply by 8 to get the width, and also

subtract 4 pixels (padding).

The mixin:

@mixin bar($start,$end) $start_value: $start - 1870 margin-left: ($start_value*8) + px $length: $end - $start width: ($length*8) - 4px

Page 67: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

#jbagwell +bar(1991, 2005)

@mixin bar(1991,2005) $start_value: 1991 - 1870 = 121 margin-left: (121*8) + px = 968px $length: 2005 - 1991 = 14 width: (14*8) - 4px) = 108px

The magic:

Page 68: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

#jbagwell +bar(1991, 2005)

#jbagwell { margin-left: 968px; width: 108px;}

The magic:

Will render as:

Page 69: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

#canson { margin-left: 8px; width: 204px; }#jorourke { margin-left: 16px; width: 164px; }#pgalvin { margin-left: 40px; width: 132px; }#kkelly { margin-left: 64px; width: 116px; }#mward { margin-left: 64px; width: 124px; }#dbrouthers { margin-left: 72px; width: 196px; }#mwelch { margin-left: 80px; width: 92px; }#tkeefe { margin-left: 80px; width: 100px; }#rconnor { margin-left: 80px; width: 132px; }#bewing { margin-left: 80px; width: 132px; }#cradbourn { margin-left: 88px; width: 76px; }#jclarkson { margin-left: 96px; width: 92px; }#bmcphee { margin-left: 96px; width: 132px; }#tmccarthy { margin-left: 112px; width: 92px; }#sthompson { margin-left: 120px; width: 164px; }

Repeat:

Page 71: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Wrapping Up

Page 72: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Installation$ sudo gem install haml

c:\> ruby gem install haml

Page 73: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

$ sass --watch ./sass/:./css/ # all .sass files compiled into ./css $ sass --update \sass/style.sass:css/style.css# ... style.sass => style.css

Compiling?

Page 74: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Compiling?... on the what?

blech...

Page 75: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Compiling?... on the what?

blech...

Page 76: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Compress / Minify~/sites/designsponge joel $ ls -hal style.css -rw-r--r-- 1 joel staff 32K Mar 18 11:26 style.css

~/sites/designsponge joel $ cp style.css style.scss

~/sites/designsponge joel $ sass -t compressed style.scss style_compressed.css

~/sites/designsponge joel $ ls -hal *.*css-rw-r--r-- 1 joel staff 32K Mar 18 11:26 style.css-rw-r--r-- 1 joel staff 32K Mar 18 11:33 style.scss-rw-r--r-- 1 joel staff 26K Mar 18 11:34 style_compressed.css

Page 77: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Compress / Minify

Page 79: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Joel @jayroh

Adam @adarowski

Page 80: Sassive Aggressive: Using Sass to Make Your Life Easier (NSWG Version)

Questions?


Top Related