raleigh web design meetup group - sass presentation

37
Syntactically Awesome Style Sheets

Upload: daniel-yuschick

Post on 03-Jul-2015

191 views

Category:

Design


1 download

DESCRIPTION

Slides from the Raleigh Web Design Meetup Group discussion on Sass 10/14/2014

TRANSCRIPT

Page 1: Raleigh Web Design Meetup Group - Sass Presentation

Syntactically Awesome Style Sheets

Page 2: Raleigh Web Design Meetup Group - Sass Presentation

Getting Started

Command Line• http://rubyinstaller.org/• Open Ruby CMD -> gem install sass• Sass –v to check version

• Navigate to styles directory• ‘Watch” the .scss file for updates

• sass --watch main.scss:main.css• sass --watch main.scss:main.css --style compressed

• Style Types:• nested, expanded, compact, compressed

Page 3: Raleigh Web Design Meetup Group - Sass Presentation

Getting Started

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

Page 4: Raleigh Web Design Meetup Group - Sass Presentation

Getting Started

Scout allows the configuration of individual project settings and compiling formats.

Page 5: Raleigh Web Design Meetup Group - Sass Presentation

The Benefits of Detecting Redundant Styles

Page 6: Raleigh Web Design Meetup Group - Sass Presentation

A cleaner, more organized working codebase Quicker updates and creation of styles Optimized and more efficient compiled CSS Save time from bottlenecks

(ie: vendor-prefixes)

Page 7: Raleigh Web Design Meetup Group - Sass Presentation

Getting Cozy with Nesting

Page 8: Raleigh Web Design Meetup Group - Sass Presentation

#main-list {list-style: none;float: left;margin: 0;li {

padding: 5px 10px;background: #333;a {

color: #333;text-decoration: none;

}}

}

Getting Cozy with Nesting

#main-list {list-style: none;float: left;margin: 0;

}#main-list li {

padding: 5px 10px;background: #333;

}#main-list li a {

color: #333;text-decoration: none;

}

Page 9: Raleigh Web Design Meetup Group - Sass Presentation

a {text-decoration: none;color: #333;&:hover {

color: #aaa;}

}

Getting Cozy with Nesting

.featured-image {display: none;&.active {

display: block;}

}

a {text-decoration: none;color: #333;

}a:hover {

color: #aaa;}

.featured-image {display: none;

}.featured-image.active {

display: block;}

Page 10: Raleigh Web Design Meetup Group - Sass Presentation

Consistency through $Variables

Page 11: Raleigh Web Design Meetup Group - Sass Presentation

$background-color: #58a611;

$img-path: “img/";

$isSet: true;

$margins: 1em 1.5em 0 0;

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

Consistency through $Variables

Variables Types

Page 12: Raleigh Web Design Meetup Group - Sass Presentation

$background-color: #58a611;$img-path: “img/";

body {background: url(#{$img-path}/bg.jpg) $background-color;

}

Consistency through $Variables

body {background: url(img/bg.jpg) #58a611;

}

Page 13: Raleigh Web Design Meetup Group - Sass Presentation

Breaking Out the @Mixins

Page 14: Raleigh Web Design Meetup Group - Sass Presentation

@mixin the-mixin-name() {

// Block of Styles

}

Breaking Out the @Mixins

Basic Syntax

.theClass {@include the-mixin-name;

}

Page 15: Raleigh Web Design Meetup Group - Sass Presentation

@mixin the-mixin-name($theSize) {

width: $theSize + px;

}

Breaking Out the @Mixins

Parameter Syntax

.theClass {@include the-mixin-name(100);

}

.theClass {width: 100px;

}

Page 16: Raleigh Web Design Meetup Group - Sass Presentation

@mixin the-mixin-name($theSize: 50) {

width: $theSize + px;

}

Breaking Out the @Mixins

Parameter Defaults Syntax

.theClass {@include the-mixin-name();

}

.theClass {width: 50px;

}

Page 17: Raleigh Web Design Meetup Group - Sass Presentation

@mixin color-class($theName, $theColor) {.#{$theName} {

color: $theColor; }

}

Breaking Out the @Mixins

.blueberry {color: #1f3e68;

}

@include color-class(‘blueberry', #1f3e68);

Page 18: Raleigh Web Design Meetup Group - Sass Presentation

@mixin color-class($theName, $theColor) {.#{$theName}, .#{$theName} a, .#{$theName} a:visited, .#{$theName} a:link, .#{$theName} a:active {

color: $theColor;}.#{$theName} a:hover {

color: lighten($theColor, 10%);}

}

Breaking Out the @Mixins

.blueberry, .blueberry a, .blueberry a:visited, .blueberry a:link, .blueberry a:active {color: #1f3e68;

}

.blueberry a:hover {color: #2b558f;

}

Page 19: Raleigh Web Design Meetup Group - Sass Presentation

Breaking Out the @Mixins

http://chir.ag/projects/name-that-color/

Page 20: Raleigh Web Design Meetup Group - Sass Presentation

$context: 14;@mixin font-class($font, $line: $font) {

$line: ($line / $font);$font: ($font / $context);font-size: $font + em;line-height: $line + em;

}

Breaking Out the @Mixins

.medium {@include font-class(16,19);

}

.medium {font-size: 1.14286em;line-height: 1.1875em;

}

Page 21: Raleigh Web Design Meetup Group - Sass Presentation

@mixin font-family($fam, $file, $class) {@font-face {font-family: '#{$fam}';src: url('#{$font-path}#{$file}.eot');src: url('#{$font-path}#{$file}.eot?#iefix') format('embedded-opentype'),

url('#{$font-path}#{$file}.woff') format('woff'),url('#{$font-path}#{$file}.ttf') format('truetype'),url('#{$font-path}#{$file}.svg##{$fam}') format('svg');

font-weight: normal;font-style: normal;}

.#{$class} {font-family: '#{$fam}';

}}

Breaking Out the @Mixins

Page 22: Raleigh Web Design Meetup Group - Sass Presentation

@font-face {font-family: "helvlightregular";src: url("fonts/heln.eot");src: url("fonts/heln.eot?#iefix") format("embedded-opentype"), url("fonts/heln.woff") format("woff"), url("fonts/heln.ttf")

format("truetype"), url("fonts/heln.svg#helvlightregular") format("svg");font-weight: normal;font-style: normal;

}

.helvlightregular {font-family: "helvlightregular";

}

Breaking Out the @Mixins

@include font-family('helvlightregular','heln','helvlightregular');

Page 23: Raleigh Web Design Meetup Group - Sass Presentation

@mixin transform($style) {-webkit-transform: #{$style};-moz-transform: #{$style};-ms-transform: #{$style};-o-transform: #{$style};transform: #{$style};

}

Breaking Out the @Mixins

@include transform(rotate(6deg)); -webkit-transform: rotate(6deg);-moz-transform: rotate(6deg);-ms-transform: rotate(6deg);-o-transform: rotate(6deg);transform: rotate(6deg);

Page 24: Raleigh Web Design Meetup Group - Sass Presentation

Getting @Functional

Page 25: Raleigh Web Design Meetup Group - Sass Presentation

$context: 14;@function element-size($size, $theContext:$context) {

$size: ($size / $theContext);@return $size + em;

}

Getting @Functional

.pineapple {width: element-size(300);height: auto;border: 0;

}

.pineapple {width: 21.42857em;height: auto;border: 0;

}

Page 26: Raleigh Web Design Meetup Group - Sass Presentation

Under One…Maybe Two Conditions

Page 27: Raleigh Web Design Meetup Group - Sass Presentation

@mixin yin-yang($isActive) {@if ($isActive) {

display: block;} @else {

display: none;}

Under One…Maybe Two Conditions

.yang {@include yin-yang(true);

}

.yang {display: block;

}

Page 28: Raleigh Web Design Meetup Group - Sass Presentation

@mixin general-styles($theView) {#header-main {

@if $theView == full or $theView == mid or $theView == tablet {padding: 3px 0;height: element-size(100);

} @else if $theView == smart {height: element-size(50);

} @else {height: element-size(170);

}}

}

Under One…Maybe Two Conditions

@include general-styles(full);

Page 29: Raleigh Web Design Meetup Group - Sass Presentation

@media only screen and (max-width: 25.875em) {@include universal-styles(dumb);@include global-styles(dumb);

}@media only screen and (min-width: 25.9375em) and (max-width: 39.3125em) {

@include universal-styles(smart);@include global-styles(smart);

}@media only screen and (min-width: 39.375em) and (max-width: 54.625em) {

@include universal-styles(tablet);@include global-styles(tablet);

}@media only screen and (min-width: 54.6875em) and (max-width: 64.9375em) {

@include universal-styles(mid);@include global-styles(mid);

}@media only screen and (min-width: 65em) {

@include universal-styles(full);@include global-styles(full);

}

Under One…Maybe Two Conditions

Page 30: Raleigh Web Design Meetup Group - Sass Presentation

Getting Straight with Loops

Page 31: Raleigh Web Design Meetup Group - Sass Presentation

@for- @for $var from <start> through <end> // Includes a loop for the <end> value- @for $var from <start> to <end> // Stops looping when <end> is reached

@each- @each $var in <list>

@while- @while <condition is true> (ie: $i < 10)

Getting Straight with Loops

Basic Syntax

Page 32: Raleigh Web Design Meetup Group - Sass Presentation

@for $i from 1 to 4 {.theClass-#{$i} {

width: #{$i}50px;}

}

Getting Straight with Loops

@for Loop

.theClass-1 {width: 150px;

}

.theClass-2 {width: 250px;

}

.theClass-3 {width: 350px;

}@for $i from 1 through 4 {.theClass-#{$i} {

width: #{$i}50px;}

}

.theClass-4 {width: 450px;

}

Page 33: Raleigh Web Design Meetup Group - Sass Presentation

$countries: sweden, denmark, finland, norway, germany;@each $country in $countries {

.flag-#{$country} {background: url(img/#{$country}.png);

}}

Getting Straight with Loops

@each Loop

.flag-sweden {background: url(img/sweden.png);

}

.flag-denmark {background: url(img/denmark.png);

}

.flag-finland {background: url(img/finland.png);

}

.flag-norway {background: url(img/norway.png);

}

.flag-germany {background: url(img/germany.png);

}

Page 34: Raleigh Web Design Meetup Group - Sass Presentation

$countries: (sweden: #006699, denmark: #cc0000, finland: #fff, norway: #ef2b2c);@each $country, $color in $countries {

.flag-#{$country} {background: url(img/#{$country}.png) $color;

}}

Getting Straight with Loops

@each Loop

.flag-sweden {background: url(img/sweden.png) #006699; }

.flag-denmark {background: url(img/denmark.png) #cc0000; }

.flag-finland {background: url(img/finland.png) #fff; }

.flag-norway {background: url(img/norway.png) #ef2b2c; }

Page 35: Raleigh Web Design Meetup Group - Sass Presentation

$hotspots: 3;$i: 1;

@while $i <= $hotspots {.hotspot-#{$i} {

top: 100px;left: 100px;

}$i: $i+1;

}

Getting Straight with Loops

@while Loop

.hotspot-1 {top: 100px;left: 100px;

}

.hotspot-2 {top: 100px;left: 100px;

}

.hotspot-3 {top: 100px;left: 100px;

}

Page 36: Raleigh Web Design Meetup Group - Sass Presentation

http://www.bourbon.io

Page 37: Raleigh Web Design Meetup Group - Sass Presentation

http://sass-lang.com/@Yuschick