Slide 1

Slide 1 text

JINA BOLTON SENIOR PRODUCT DESIGNER SALESFORCE UX Sass Basics #2

Slide 2

Slide 2 text

…PREVIOUSLY IN Sass Basics #1 INTRODUCTION TO SASS COMMENTING NESTING VARIABLES

Slide 3

Slide 3 text

Sass Basics #2 INTRODUCTION TO MIXINS PASSING ARGUMENTS CONTENT BLOCKS MIXIN LIBRARIES

Slide 4

Slide 4 text

SASSMEISTER.COM

Slide 5

Slide 5 text

CSS Output SCSS .thingy { background: #eee; color: #444; } @mixin module { background: #eee; color: #444; } .thingy { @include module; }

Slide 6

Slide 6 text

Sass SCSS =module background: #eee color: #444 @mixin module { background: #eee; color: #444; }

Slide 7

Slide 7 text

You can nest selectors in a mixin.

Slide 8

Slide 8 text

CSS Output SCSS .thingy { background: #eee; } .thingy .this { color: #444; } @mixin module { background: #eee; .this { color: #444; } } .thingy { @include module; }

Slide 9

Slide 9 text

You can include mixins outside of rules…

Slide 10

Slide 10 text

CSS Output SCSS .this { color: #444; } .that { color: #444; } @mixin module { .this { color: #444; } .that { color: #ccc; } } @include module;

Slide 11

Slide 11 text

…unless you directly define properties or parent selectors.

Slide 12

Slide 12 text

CSS Output SCSS Invalid CSS after "...lor: #ccc; }} ": expected "{", was "@include module;" @mixin module { color: #444; &.that { color: #ccc; } } @include module;

Slide 13

Slide 13 text

You can include other mixins in mixins.

Slide 14

Slide 14 text

CSS Output SCSS .thingy { background: #222; color: #ccc; } .thingy a { color: #fff; } @mixin dark-theme { background: #222; color: #ccc; } @mixin module { @include dark-theme; a { color: #fff; } } .thingy { @include module; }

Slide 15

Slide 15 text

You can pass in arguments.

Slide 16

Slide 16 text

CSS Output SCSS .thingy1 { background: #eee; color: #444; } .thingy2 { background: #eee; color: purple; } .thingy3 { background: green; color: red; } .thingy4 { background: blue; color: #444; } @mixin module($text: #444, $background: #eee) { background: $background; color: $text; } .thingy1 { @include module; } .thingy2 { @include module(purple); } .thingy3 { @include module(red, green); } .thingy4 { @include module($background: blue); }

Slide 17

Slide 17 text

You can pass in content blocks.

Slide 18

Slide 18 text

CSS Output SCSS * html .thingy1 { display: inline; } @mixin ie6-only { * html { @content; } } @include ie6-only { .thingy1 { display: inline; } }

Slide 19

Slide 19 text

With great power, comes great responsibility ;-)

Slide 20

Slide 20 text

Every time you use a Mixin, you output that code again.

Slide 21

Slide 21 text

SASS-LANG.COM

Slide 22

Slide 22 text

USE SASSMEISTER TO EXPERIMENT WITH MIXINS. BUILD A BASIC MIXIN LIBRARY NEXT WEEK: EXTENDING & PLACEHOLDER SELECTORS your homework