SlideShare uma empresa Scribd logo
1 de 54
COMPASS/SASS
Saturday 6th of March — Barcamp Antwerpen — Johan Ronsse
Hi! I’m Johan.
I work at Netlash, a web agency
I also run a tiny webdesign company
First things rst:

Wat is Sass?
Sass makes CSS fun again. Sass is CSS,
plus nested rules, variables, mixins, and
more, all in a concise, readable syntax.
                             Hampton Catlin
                             Originally wrote Sass
Why Sass?
•   Your CSS is cleaner and easier to maintain
•   Much better separation of style and content
•   Separate les without performance loss
•   Automatic cross-browser CSS
•   Your CSS automatically gets mini ed
Compass Compiler:




Recompiles your CSS every time you save your Sass.
project/src/              project/css/

screen.sass
     _reset.sass                         screen.css
     _typography.sass

     _structure.sass                     print.css
             _layout.sass     compiler
     _ui_core.sass                       ie7.css
             _datagrid.sass
             _calendar.sass
                                         ie6.css
print.sass
ie6.sass

ie7.sass
1. Variables
2. Mixins
3. Imports
Consider the following CSS:



             body {
                 background: #F1F5FA;
             }
We de ne the background color as a constant:




                 !lightblue = #F1F5FA
We’ll use the following Sass to get the same output:



             !lightblue = #F1F5FA

             body
               :background = !lightblue
1. Variables
2. Mixins
3. Imports
Consider the following CSS:


               .rounded-corners {
                   -webkit-border-radius: 3px;
                   -moz-border-radius: 3px;
                   border-radius: 3px;
               }
We’ll de ne this as a mixin:


                =border-radius
                  :-webkit-border-radius 3px
                  :-moz-border-radius 3px
                  :border-radius 3px
Now we apply this mixin to a selector:


                       h2
                         :background red
                         :padding 3px
                         +border-radius
Since CSS classes are the only way to abstract,
our HTML often looks like this:


<div id="content" class="clearfix col col-4 p-col-2">
    <h2 class="rounded-corners abs red">Hello world</h2>
    <p>Lorem ipsum dolor sit amet...</p>
</div>
Using Sass, we can keep it clean and semantic:



      <div id="content">
          <h2>Hello world</h2>
          <p>Lorem ipsum dolor sit amet...</p>
      </div>
Mixins can have arguments and defaults:


    !default_border_radius ||= 5px

    =border-radius(!radius = !default_border_radius)
      border-radius= !radius
      -moz-border-radius= !radius
      -webkit-border-radius= !radius
Regular mixin use (selector), override default (selector2)


    #selector
      +border-radius

    // Override default border radius for this selector
    #selector2
      +border-radius("3px")
De ne once, reuse.
Someone makes a cool plugin:
Install plugin:
sudo gem install fancy-buttons



Require plugin:
require 'fancy-buttons'
1. Variables
2. Mixins
3. Imports
Let’s say we often use border-radius in our projects.
We’ll import the Compass Core CSS3 module:

@import compass/css3

!default_border_radius ||= 5px                                                             //
                                                                                             Round top-right radius only
=border-radius(!radius = !default_border_radius)
  border-radius= !radius                                                                   =border-top-right-radius(!radius = !default_border_radius)
  -moz-border-radius= !radius                                                                +border-corner-radius("top", "right", !radius)
  -webkit-border-radius= !radius
                                                                                           //
//                                                                                           Round bottom-left radius only
     Round all borders by a specific amount, defaults to value of !default_border_radius
                                                                                           =border-bottom-left-radius(!radius = !default_border_radius)
=border-radius(!radius = !default_border_radius)                                             +border-corner-radius("bottom", "left", !radius)
  border-radius= !radius
  -moz-border-radius= !radius                                                              //
  -webkit-border-radius= !radius                                                             Round bottom-right radius only

//                                                                                         =border-bottom-right-radius(!radius = !default_border_radius)
     Round radius at position by amount.                                                     +border-corner-radius("bottom", "right", !radius)

     * values for !vert: "top", "bottom"                                                   // Round top corners by amount
     * values for !horz: "left", "right"                                                   =border-top-radius(!radius = !default_border_radius)
                                                                                             +border-top-left-radius(!radius)
=border-corner-radius(!vert, !horz, !radius = !default_border_radius)                        +border-top-right-radius(!radius)
  border-#{!vert}-#{!horz}-radius= !radius
  -moz-border-radius-#{!vert}#{!horz}= !radius                                             // Round right corners by amount
  -webkit-border-#{!vert}-#{!horz}-radius= !radius                                         =border-right-radius(!radius = !default_border_radius)
                                                                                             +border-top-right-radius(!radius)
//                                                                                           +border-bottom-right-radius(!radius)
Now we have access to a lot of mixins:

   Round all borders by a speci c amount   +border-radius

   Round top-left radius only              +border-top-left-radius

   Round top-right radius only             +border-top-right-radius

   Round bottom-left radius only           +border-bottom-left-radius

   Round bottom-right radius only          +border-bottom-right-radius

   Round top corners by amount             +border-top-radius

   Round right corners by amount           +border-right-radius

   Round bottom corners by amount          +border-bottom-radius

   Round left corners by amount            +border-left-radius
These are the other CSS3 modules:

                   @import   css3/border_radius.sass
                   @import   css3/inline_block.sass
                   @import   css3/opacity.sass
                   @import   css3/box_shadow.sass
                   @import   css3/text_shadow.sass
                   @import   css3/columns.sass
                   @import   css3/box_sizing.sass
                   @import   css3/gradient.sass
                   @import   css3/background_clip.sass
                   @import   css3/background_origin.sass
                   @import   css3/background_size.sass
                   @import   css3/font_face.sass
                   @import   css3/transform.sass
                   @import   css3/transition.sass
Another example. Let’s say we want to make an
element transparent. The CSS way:



                       h2 {
                              opacity: 0.5;
                       }
Opacity browser support (without speci c syntax)

             Safari 4                      Yes
             Safari 3                      Yes
             Google Chrome (latest)        Yes
             Firefox 3+                    Yes
             Firefox 2                     No
             Opera (latest)                Yes
             Internet Explorer 8           No
             Internet Explorer 7           No
             Internet Explorer 6           No
Opacity browser support (with speci c syntax)

             Safari 4                      Yes
             Safari 3                      Yes
             Google Chrome (latest)        Yes
             Firefox 3+                    Yes
             Firefox 2                     Yes
             Opera (latest)                Yes
             Internet Explorer 8           Yes
             Internet Explorer 7           Yes
             Internet Explorer 6           Yes
Source code for Compass Core CSS3 opacity mixin



=opacity(!opacity)
  opacity= !opacity
  -moz-opacity= !opacity
  -khtml-opacity= !opacity
  -ms-filter= "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + round(!opacity*100) + ")"
  filter= "alpha(opacity=" + round(!opacity*100) + ")"
Some interesting things going on here:



=opacity(!opacity)
  opacity= !opacity
  -moz-opacity= !opacity
  -khtml-opacity= !opacity
  -ms-filter= "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + round(!opacity*100) + ")"
  filter= "alpha(opacity=" + round(!opacity*100) + ")"




                                round() function                         arithmetic!
Back to our example. In CSS you would do this:




                       h2 {
                              opacity: 0.5;
                       }
Then... fuck... have to support IE.
*Google to lookup code*


                h2 {
                     opacity: 0.5;
                     filter: alpha(opacity="50");
                }
WHAT? The syntax changed for IE8?
*Google again to lookup code*


           h2 {
                opacity: 0.5;
                filter: alpha(opacity="50");
                -ms-filter: "alpha(opacity=50)";
           }
Hypothetically a new browser called Fuzzy hits the
browser market by a storm, and has a proprietary
syntax for opacity.


            h2 {
                -fuzzy-opacity: "alpha(50)";
            }




Almost all of your websites are broken now.
Update 59 websites I made since new browser?


                   No!
Things that are wrong here:
•   Copy/pasting the same code for the nth time
•   Breaking your work ow by going to another site
•   Have to remember all weird browser inconsistencies
•   Code might break in the future
Now... the better way.


     The Sass Way.
This is all we have to do to make the opacity code work:



                      @import compass/css3

                      h2
                        +opacity(50)
Sass/Compass compiles to:

   h2 {
       opacity: 0.5;
       -moz-opacity: 0.5;
       -khtml-opacity: 0.5;
       -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
       filter: alpha(opacity=50);
   }




Code that works, cross-browser.
Now, since we’re using a compiler so we can do other things we
couldn’t do before.


For example, outputting mini ed CSS by default:

             output_style = :compressed
!blueprint_grid_columns = 8
Since Compass/Sass does          !blueprint_grid_width = 40px
arithmetic we can do grid        @import blueprint
calculations. This is the code   .two-col
you need to create a two           +container
                                   background-color: #ccc
column grid, using the             #header, #footer
                                     +column(8)
Compass port of Blueprint:         #sidebar
                                     +column(3)
                                   #content
                                     +column(5, true)
A little side by side comparison:
!blueprint_grid_columns = 8    .two-col {
!blueprint_grid_width = 40px     width: 390px;
                                 margin: 0 auto;
@import blueprint                overflow: hidden;
                                 display: inline-block;
.two-col                         background-color: #ccc;
  +container                   }
  background-color: #ccc       .two-col {
  #header, #footer               display: block;
    +column(8)                 }
  #sidebar                     .two-col #header, .two-col #footer {
    +column(3)                   display: inline;
  #content                       float: left;
    +column(5, true)             margin-right: 10px;
                                 width: 390px;
                               }
                               * html .two-col #header, * html .two-col #footer {
                                 overflow-x: hidden;
                               }
                               .two-col #sidebar {
                                 display: inline;
                                 float: left;
                                 margin-right: 10px;
                                 width: 140px;
                               }
                               * html .two-col #sidebar {
                                 overflow-x: hidden;
                               }
                               .two-col #content {
                                 display: inline;
                                 float: left;
                                 margin-right: 0;
                                 width: 240px;
                               }
                               * html .two-col #content {
                                 overflow-x: hidden;
                               }
Q: Why is the Sass code so much leaner?
               .two-col
                 +container
                 background-color: #ccc
                 #header, #footer
                   +column(8)
                 #sidebar
                   +column(3)
                 #content
                   +column(5, true)




A: it relies on whitespace, just like Ruby and Python
We can create custom functions that extend Compass/Sass:

                         Decode image to base64 to save on HTTP
       inline_images()
                         requests (non IE only)

                         Part of Compass colors plugin: this
       darken(10)
                         example darkens a color by 10%


                   (and save us time!)
             (and make our websites better!)
If Compass is part of your deployment process, your
     live sites will always have mini ed CSS.
Hypothetically a new browser called Fuzzy hits the
browser market by a storm, and has a proprietary
syntax for opacity.


            h2 {
                -fuzzy-opacity: "alpha(75)";
            }




Almost all of your websites are broken now.
gem update compass,
    recompile,
      done!
Theory:
  Assuming you use a version control system, with a
branch re ecting the live site, have good deployment
 strategy, you can effectively patch your 92 websites
               in less than 10 minutes.

             (Of course, something will go wrong.)
Fork Compass on Github
http://github.com/chriseppstein/compass
Read my blog
http://www.wolfslittlestore.be
johan@johanronsse.be
http://www.netlash.com

Mais conteúdo relacionado

Mais procurados

Getting Sassy with CSS
Getting Sassy with CSSGetting Sassy with CSS
Getting Sassy with CSSJulie Cameron
 
CSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondCSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondDenise Jacobs
 
Colors In CSS3
Colors In CSS3Colors In CSS3
Colors In CSS3Lea Verou
 
Intro to css & sass
Intro to css & sassIntro to css & sass
Intro to css & sassSean Wolfe
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With LessDavid Engel
 
Spectrum 2015 going online with style - an intro to css
Spectrum 2015   going online with style - an intro to cssSpectrum 2015   going online with style - an intro to css
Spectrum 2015 going online with style - an intro to cssNeil Perlin
 
BDUG Responsive Web Theming - 7/23/12
BDUG Responsive Web Theming - 7/23/12BDUG Responsive Web Theming - 7/23/12
BDUG Responsive Web Theming - 7/23/12ucbdrupal
 
Sass and Compass - Getting Started
Sass and Compass - Getting StartedSass and Compass - Getting Started
Sass and Compass - Getting Startededgincvg
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondAndy Stratton
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)emrox
 
October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101Eric Sembrat
 
CSS3: Simply Responsive
CSS3: Simply ResponsiveCSS3: Simply Responsive
CSS3: Simply ResponsiveDenise Jacobs
 

Mais procurados (20)

Getting Sassy with CSS
Getting Sassy with CSSGetting Sassy with CSS
Getting Sassy with CSS
 
Sass
SassSass
Sass
 
Compass/Sass
Compass/SassCompass/Sass
Compass/Sass
 
Intro to SASS CSS
Intro to SASS CSSIntro to SASS CSS
Intro to SASS CSS
 
Sass_Cubet seminar
Sass_Cubet seminarSass_Cubet seminar
Sass_Cubet seminar
 
Sass compass
Sass compassSass compass
Sass compass
 
CSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondCSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to Respond
 
Colors In CSS3
Colors In CSS3Colors In CSS3
Colors In CSS3
 
Intro to css & sass
Intro to css & sassIntro to css & sass
Intro to css & sass
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With Less
 
Spectrum 2015 going online with style - an intro to css
Spectrum 2015   going online with style - an intro to cssSpectrum 2015   going online with style - an intro to css
Spectrum 2015 going online with style - an intro to css
 
BDUG Responsive Web Theming - 7/23/12
BDUG Responsive Web Theming - 7/23/12BDUG Responsive Web Theming - 7/23/12
BDUG Responsive Web Theming - 7/23/12
 
Sass and Compass - Getting Started
Sass and Compass - Getting StartedSass and Compass - Getting Started
Sass and Compass - Getting Started
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and Beyond
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101
 
Compass
CompassCompass
Compass
 
CSS Extenders
CSS ExtendersCSS Extenders
CSS Extenders
 
Less css
Less cssLess css
Less css
 
CSS3: Simply Responsive
CSS3: Simply ResponsiveCSS3: Simply Responsive
CSS3: Simply Responsive
 

Destaque

CSS3 : Animation ,Transitions, Gradients
CSS3 : Animation ,Transitions, GradientsCSS3 : Animation ,Transitions, Gradients
CSS3 : Animation ,Transitions, GradientsJatin_23
 
Css3 animation
Css3 animationCss3 animation
Css3 animationTed Hsu
 
LESS, SASS, HAML: 4 буквы, изменившие frontend development
LESS, SASS, HAML: 4 буквы, изменившие frontend developmentLESS, SASS, HAML: 4 буквы, изменившие frontend development
LESS, SASS, HAML: 4 буквы, изменившие frontend developmentKonstantin Kudryashov
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010Nicholas Zakas
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheetschriseppstein
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementationdavejohnson
 

Destaque (9)

CSS3 : Animation ,Transitions, Gradients
CSS3 : Animation ,Transitions, GradientsCSS3 : Animation ,Transitions, Gradients
CSS3 : Animation ,Transitions, Gradients
 
Workshop Advance CSS3 animation
Workshop Advance CSS3 animationWorkshop Advance CSS3 animation
Workshop Advance CSS3 animation
 
Sass: Introduction
Sass: IntroductionSass: Introduction
Sass: Introduction
 
Css3 animation
Css3 animationCss3 animation
Css3 animation
 
LESS, SASS, HAML: 4 буквы, изменившие frontend development
LESS, SASS, HAML: 4 буквы, изменившие frontend developmentLESS, SASS, HAML: 4 буквы, изменившие frontend development
LESS, SASS, HAML: 4 буквы, изменившие frontend development
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
 
CSS3
CSS3CSS3
CSS3
 

Semelhante a COMPASS/SASS Guide

Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compassdrywallbmb
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentationMario Noble
 
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)Adam Darowski
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid PrototypingEven Wu
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application DesignBryce Kerley
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with SassRob Friesel
 
Using Sass - Building on CSS
Using Sass - Building on CSSUsing Sass - Building on CSS
Using Sass - Building on CSSSayanee Basu
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassClaudina Sarahe
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)elliando dias
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESSItai Koren
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockMarco Pinheiro
 
CSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie DustCSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie DustKyle Adams
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compassChris Lee
 
Rails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineRails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineJames Daniels
 
LESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageKatsunori Tanaka
 
Creating Responsive Drupal Sites with Zen Grids and the Zen 5 Theme
Creating Responsive Drupal Sites with Zen Grids and the Zen 5 ThemeCreating Responsive Drupal Sites with Zen Grids and the Zen 5 Theme
Creating Responsive Drupal Sites with Zen Grids and the Zen 5 ThemeAcquia
 

Semelhante a COMPASS/SASS Guide (20)

Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compass
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
 
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
Sassive Aggressive: Using Sass to Make Your Life Easier (Refresh Boston Version)
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
 
Using Sass - Building on CSS
Using Sass - Building on CSSUsing Sass - Building on CSS
Using Sass - Building on CSS
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, Greensock
 
CSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie DustCSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie Dust
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
Rails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineRails 3.1 Asset Pipeline
Rails 3.1 Asset Pipeline
 
LESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet language
 
Creating Responsive Drupal Sites with Zen Grids and the Zen 5 Theme
Creating Responsive Drupal Sites with Zen Grids and the Zen 5 ThemeCreating Responsive Drupal Sites with Zen Grids and the Zen 5 Theme
Creating Responsive Drupal Sites with Zen Grids and the Zen 5 Theme
 

Mais de Johan Ronsse

iOS design: a case study
iOS design: a case studyiOS design: a case study
iOS design: a case studyJohan Ronsse
 
Designing better user interfaces
Designing better user interfacesDesigning better user interfaces
Designing better user interfacesJohan Ronsse
 
Design for developers
Design for developersDesign for developers
Design for developersJohan Ronsse
 
The jump to freelance
The jump to freelanceThe jump to freelance
The jump to freelanceJohan Ronsse
 
Wolf fronteers 2010
Wolf fronteers 2010Wolf fronteers 2010
Wolf fronteers 2010Johan Ronsse
 
jQuery for designers
jQuery for designersjQuery for designers
jQuery for designersJohan Ronsse
 
Meester van het CSS universum worden + Opvolging “Craftsmanship”
Meester van het CSS universum worden + Opvolging “Craftsmanship”Meester van het CSS universum worden + Opvolging “Craftsmanship”
Meester van het CSS universum worden + Opvolging “Craftsmanship”Johan Ronsse
 
Webdesign De Middelmaat Overstijgen
Webdesign De Middelmaat OverstijgenWebdesign De Middelmaat Overstijgen
Webdesign De Middelmaat OverstijgenJohan Ronsse
 

Mais de Johan Ronsse (11)

What is Bedrock?
What is Bedrock?What is Bedrock?
What is Bedrock?
 
iOS design: a case study
iOS design: a case studyiOS design: a case study
iOS design: a case study
 
Designing better user interfaces
Designing better user interfacesDesigning better user interfaces
Designing better user interfaces
 
Design for developers
Design for developersDesign for developers
Design for developers
 
The jump to freelance
The jump to freelanceThe jump to freelance
The jump to freelance
 
Wolf fronteers 2010
Wolf fronteers 2010Wolf fronteers 2010
Wolf fronteers 2010
 
CSS3 now
CSS3 nowCSS3 now
CSS3 now
 
jQuery for designers
jQuery for designersjQuery for designers
jQuery for designers
 
Workflow
WorkflowWorkflow
Workflow
 
Meester van het CSS universum worden + Opvolging “Craftsmanship”
Meester van het CSS universum worden + Opvolging “Craftsmanship”Meester van het CSS universum worden + Opvolging “Craftsmanship”
Meester van het CSS universum worden + Opvolging “Craftsmanship”
 
Webdesign De Middelmaat Overstijgen
Webdesign De Middelmaat OverstijgenWebdesign De Middelmaat Overstijgen
Webdesign De Middelmaat Overstijgen
 

Último

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Último (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

COMPASS/SASS Guide

  • 1. COMPASS/SASS Saturday 6th of March — Barcamp Antwerpen — Johan Ronsse
  • 3. I work at Netlash, a web agency
  • 4. I also run a tiny webdesign company
  • 6. Sass makes CSS fun again. Sass is CSS, plus nested rules, variables, mixins, and more, all in a concise, readable syntax. Hampton Catlin Originally wrote Sass
  • 7. Why Sass? • Your CSS is cleaner and easier to maintain • Much better separation of style and content • Separate les without performance loss • Automatic cross-browser CSS • Your CSS automatically gets mini ed
  • 8. Compass Compiler: Recompiles your CSS every time you save your Sass.
  • 9. project/src/ project/css/ screen.sass _reset.sass screen.css _typography.sass _structure.sass print.css _layout.sass compiler _ui_core.sass ie7.css _datagrid.sass _calendar.sass ie6.css print.sass ie6.sass ie7.sass
  • 11. Consider the following CSS: body { background: #F1F5FA; }
  • 12. We de ne the background color as a constant: !lightblue = #F1F5FA
  • 13. We’ll use the following Sass to get the same output: !lightblue = #F1F5FA body :background = !lightblue
  • 15. Consider the following CSS: .rounded-corners { -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
  • 16. We’ll de ne this as a mixin: =border-radius :-webkit-border-radius 3px :-moz-border-radius 3px :border-radius 3px
  • 17. Now we apply this mixin to a selector: h2 :background red :padding 3px +border-radius
  • 18. Since CSS classes are the only way to abstract, our HTML often looks like this: <div id="content" class="clearfix col col-4 p-col-2"> <h2 class="rounded-corners abs red">Hello world</h2> <p>Lorem ipsum dolor sit amet...</p> </div>
  • 19. Using Sass, we can keep it clean and semantic: <div id="content"> <h2>Hello world</h2> <p>Lorem ipsum dolor sit amet...</p> </div>
  • 20. Mixins can have arguments and defaults: !default_border_radius ||= 5px =border-radius(!radius = !default_border_radius) border-radius= !radius -moz-border-radius= !radius -webkit-border-radius= !radius
  • 21. Regular mixin use (selector), override default (selector2) #selector +border-radius // Override default border radius for this selector #selector2 +border-radius("3px")
  • 22. De ne once, reuse.
  • 23. Someone makes a cool plugin:
  • 24. Install plugin: sudo gem install fancy-buttons Require plugin: require 'fancy-buttons'
  • 26. Let’s say we often use border-radius in our projects. We’ll import the Compass Core CSS3 module: @import compass/css3 !default_border_radius ||= 5px // Round top-right radius only =border-radius(!radius = !default_border_radius) border-radius= !radius =border-top-right-radius(!radius = !default_border_radius) -moz-border-radius= !radius +border-corner-radius("top", "right", !radius) -webkit-border-radius= !radius // // Round bottom-left radius only Round all borders by a specific amount, defaults to value of !default_border_radius =border-bottom-left-radius(!radius = !default_border_radius) =border-radius(!radius = !default_border_radius) +border-corner-radius("bottom", "left", !radius) border-radius= !radius -moz-border-radius= !radius // -webkit-border-radius= !radius Round bottom-right radius only // =border-bottom-right-radius(!radius = !default_border_radius) Round radius at position by amount. +border-corner-radius("bottom", "right", !radius) * values for !vert: "top", "bottom" // Round top corners by amount * values for !horz: "left", "right" =border-top-radius(!radius = !default_border_radius) +border-top-left-radius(!radius) =border-corner-radius(!vert, !horz, !radius = !default_border_radius) +border-top-right-radius(!radius) border-#{!vert}-#{!horz}-radius= !radius -moz-border-radius-#{!vert}#{!horz}= !radius // Round right corners by amount -webkit-border-#{!vert}-#{!horz}-radius= !radius =border-right-radius(!radius = !default_border_radius) +border-top-right-radius(!radius) // +border-bottom-right-radius(!radius)
  • 27. Now we have access to a lot of mixins: Round all borders by a speci c amount +border-radius Round top-left radius only +border-top-left-radius Round top-right radius only +border-top-right-radius Round bottom-left radius only +border-bottom-left-radius Round bottom-right radius only +border-bottom-right-radius Round top corners by amount +border-top-radius Round right corners by amount +border-right-radius Round bottom corners by amount +border-bottom-radius Round left corners by amount +border-left-radius
  • 28. These are the other CSS3 modules: @import css3/border_radius.sass @import css3/inline_block.sass @import css3/opacity.sass @import css3/box_shadow.sass @import css3/text_shadow.sass @import css3/columns.sass @import css3/box_sizing.sass @import css3/gradient.sass @import css3/background_clip.sass @import css3/background_origin.sass @import css3/background_size.sass @import css3/font_face.sass @import css3/transform.sass @import css3/transition.sass
  • 29. Another example. Let’s say we want to make an element transparent. The CSS way: h2 { opacity: 0.5; }
  • 30. Opacity browser support (without speci c syntax) Safari 4 Yes Safari 3 Yes Google Chrome (latest) Yes Firefox 3+ Yes Firefox 2 No Opera (latest) Yes Internet Explorer 8 No Internet Explorer 7 No Internet Explorer 6 No
  • 31. Opacity browser support (with speci c syntax) Safari 4 Yes Safari 3 Yes Google Chrome (latest) Yes Firefox 3+ Yes Firefox 2 Yes Opera (latest) Yes Internet Explorer 8 Yes Internet Explorer 7 Yes Internet Explorer 6 Yes
  • 32. Source code for Compass Core CSS3 opacity mixin =opacity(!opacity) opacity= !opacity -moz-opacity= !opacity -khtml-opacity= !opacity -ms-filter= "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + round(!opacity*100) + ")" filter= "alpha(opacity=" + round(!opacity*100) + ")"
  • 33. Some interesting things going on here: =opacity(!opacity) opacity= !opacity -moz-opacity= !opacity -khtml-opacity= !opacity -ms-filter= "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + round(!opacity*100) + ")" filter= "alpha(opacity=" + round(!opacity*100) + ")" round() function arithmetic!
  • 34. Back to our example. In CSS you would do this: h2 { opacity: 0.5; }
  • 35. Then... fuck... have to support IE. *Google to lookup code* h2 { opacity: 0.5; filter: alpha(opacity="50"); }
  • 36. WHAT? The syntax changed for IE8? *Google again to lookup code* h2 { opacity: 0.5; filter: alpha(opacity="50"); -ms-filter: "alpha(opacity=50)"; }
  • 37. Hypothetically a new browser called Fuzzy hits the browser market by a storm, and has a proprietary syntax for opacity. h2 { -fuzzy-opacity: "alpha(50)"; } Almost all of your websites are broken now.
  • 38. Update 59 websites I made since new browser? No!
  • 39. Things that are wrong here: • Copy/pasting the same code for the nth time • Breaking your work ow by going to another site • Have to remember all weird browser inconsistencies • Code might break in the future
  • 40. Now... the better way. The Sass Way.
  • 41. This is all we have to do to make the opacity code work: @import compass/css3 h2 +opacity(50)
  • 42. Sass/Compass compiles to: h2 { opacity: 0.5; -moz-opacity: 0.5; -khtml-opacity: 0.5; -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50); filter: alpha(opacity=50); } Code that works, cross-browser.
  • 43. Now, since we’re using a compiler so we can do other things we couldn’t do before. For example, outputting mini ed CSS by default: output_style = :compressed
  • 44. !blueprint_grid_columns = 8 Since Compass/Sass does !blueprint_grid_width = 40px arithmetic we can do grid @import blueprint calculations. This is the code .two-col you need to create a two +container background-color: #ccc column grid, using the #header, #footer +column(8) Compass port of Blueprint: #sidebar +column(3) #content +column(5, true)
  • 45. A little side by side comparison: !blueprint_grid_columns = 8 .two-col { !blueprint_grid_width = 40px width: 390px; margin: 0 auto; @import blueprint overflow: hidden; display: inline-block; .two-col background-color: #ccc; +container } background-color: #ccc .two-col { #header, #footer display: block; +column(8) } #sidebar .two-col #header, .two-col #footer { +column(3) display: inline; #content float: left; +column(5, true) margin-right: 10px; width: 390px; } * html .two-col #header, * html .two-col #footer { overflow-x: hidden; } .two-col #sidebar { display: inline; float: left; margin-right: 10px; width: 140px; } * html .two-col #sidebar { overflow-x: hidden; } .two-col #content { display: inline; float: left; margin-right: 0; width: 240px; } * html .two-col #content { overflow-x: hidden; }
  • 46. Q: Why is the Sass code so much leaner? .two-col +container background-color: #ccc #header, #footer +column(8) #sidebar +column(3) #content +column(5, true) A: it relies on whitespace, just like Ruby and Python
  • 47. We can create custom functions that extend Compass/Sass: Decode image to base64 to save on HTTP inline_images() requests (non IE only) Part of Compass colors plugin: this darken(10) example darkens a color by 10% (and save us time!) (and make our websites better!)
  • 48. If Compass is part of your deployment process, your live sites will always have mini ed CSS.
  • 49. Hypothetically a new browser called Fuzzy hits the browser market by a storm, and has a proprietary syntax for opacity. h2 { -fuzzy-opacity: "alpha(75)"; } Almost all of your websites are broken now.
  • 50. gem update compass, recompile, done!
  • 51. Theory: Assuming you use a version control system, with a branch re ecting the live site, have good deployment strategy, you can effectively patch your 92 websites in less than 10 minutes. (Of course, something will go wrong.)
  • 52. Fork Compass on Github http://github.com/chriseppstein/compass

Notas do Editor