learn sass and compass quick

18
Learn Sass + Compass Quick Billy Shih - Code Fellows - May 21, 2013

Upload: billy-shih

Post on 27-Jan-2015

108 views

Category:

Technology


3 download

DESCRIPTION

Quick overview of Sass and Compass. Presented to Code Fellows May 2013. Code examples here: https://github.com/bbshih/sass_presentation

TRANSCRIPT

Page 1: Learn Sass and Compass quick

Learn Sass + Compass Quick

Billy Shih - Code Fellows - May 21, 2013

Page 2: Learn Sass and Compass quick

Demo and notes on http://github.com/bbshih/sass_presentation

Page 3: Learn Sass and Compass quick

Syntactically Awesome Stylesheets

Page 4: Learn Sass and Compass quick

1. Indented syntax (.sass)

2. SCSS (.scss)

Page 5: Learn Sass and Compass quick

.sass .scss become .css

Page 6: Learn Sass and Compass quick

VariablesNestingMixinsSelector Inheritence

Page 7: Learn Sass and Compass quick

Compass = CSS SASS Framework

Page 8: Learn Sass and Compass quick

Add to your Gemfile:

group :assets do gem 'sass-rails' # if running rails 3.1 or greater gem 'compass-rails' end

In your project directory run:

$ bundle $ bundle exec compass init

Page 9: Learn Sass and Compass quick

Rename your application.css to application.css.scss and add to the file:

@import "compass"

Create new .scss files and @import them into the application.css.scss

Page 10: Learn Sass and Compass quick

VariablesCSS SCSS

h2 { color: #ff00ee;}th { background-color: #ff00ee;}a { color: #ff00ee;}

$pink: #ff00ee;$green: #11aa00;$bright: $green;$link: $pink;h2 { color: $bright;}th { background-color: $bright;}a { color: $link;}

Page 11: Learn Sass and Compass quick

Nesting

.main { border: 5px solid green; font-size:20px;}.main th { color: red;}th { color: blue;}

.main { border: 5px solid green; font-size:20px; th { color: red; }}th { color: blue; }

Page 12: Learn Sass and Compass quick

Mixins

p { background-image: url("/assets/mindblown.gif"); height: 200px;}h1 { background-image: url("/assets/mindblown.gif"); height: 200px;}

@mixin mindblown { background-image: image-url("mindblown.gif"); height: 200px;}p { @include mindblown;}h1 { @include mindblown;}

Page 13: Learn Sass and Compass quick

Mixins w/ argument

@mixin mindblown { background-image: image-url("mindblown.gif"); height: 200px;}p { @include mindblown;}h1 { @include mindblown; height: 400px;}

@mixin mindblown($height){ background-image: image-url("mindblown.gif"); height: $height;}p { @include mindblown(200px);}h1 { @include mindblown(400px);}

Page 14: Learn Sass and Compass quick

Selector Inheritence

HTML: <div class=”alert seriousAlert”></div>

CSS:.alert { background-color: red; font-size: 20px; text-align: center;}.seriousAlert { border: 5px solid blue;

HTML: <div class=”seriousAlert”></div>

SCSS:.alert { background-color: red; font-size: 20px; text-align: center;}.seriousAlert { @extend .alert; border: 5px solid blue;}

Page 15: Learn Sass and Compass quick

Compass

.radius { -webkit-border-radius: 25px; -moz-border-radius: 25px; -ms-border-radius: 25px; -o-border-radius: 25px; border-radius: 25px;}table { border: 20px solid orange;}

.radius { @include border-radius(25px); }table { border: 20px solid orange;}

Page 16: Learn Sass and Compass quick

Compass

$base-font-size: 16px;$base-line-height: 15px;@include establish-baseline;

Page 17: Learn Sass and Compass quick

Links

•http://sass-lang.com/

•http://compass-style.org/