SlideShare ist ein Scribd-Unternehmen logo
1 von 104
Downloaden Sie, um offline zu lesen
An Introduction to
Sassy CSS
Stewart Curry




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
Who is
This Guy?

Web Designer for 15 years or so
Table-based layouts & spacer gifs
CSS changed all that
SCSS is CSS only better
woop.ie - iteration, modules, themes, templates

  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
past
                                           simple




@IRISHSTU   AN INTRODUCTION TO SASSY CSS    #REFRESHDUBLIN   18 JULY 2012
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
now
                              complicated




@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
💬



@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
design
everywhere

@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012

                                         




                                                  
 📱                                                             💻
@IRISHSTU   AN INTRODUCTION TO SASSY CSS       #REFRESHDUBLIN   18 JULY 2012
SASS MAKES
CSS FUN AGAIN
www.sass-lang.com



Basically, CSS made flexible
& awesome by adding in
cool features.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
There
                                             Will
                                           be Code

@IRISHSTU   AN INTRODUCTION TO SASSY CSS    #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
Sass                     Style with attitude

“   Sass is an extension of CSS3, adding
    nested rules, variables, mixins,
    selector inheritance, and more. It’s
    translated to well-formatted, standard
    CSS using the command line tool or a
    web-framework plugin. www.sass-lang.com




      @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
it looks like CSS
  $blue: #3bbfce;
  $margin: 16px;

.content-navigation {
  border-color: $blue;
  color: darken($blue, 9%);
}

.border {
  padding: $margin / 2;
  margin: $margin / 2;
  border-color: $blue;
}


 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
it looks like CSS but
•   it’s neater
•   it’s faster to write
•   it allows for more experimentation
•   it’s more flexible
•   it’s more manageable
•   it’s got variables!




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
so you can
•   experiment more
•   make global changes quickly
•   make reusable modules
•   use frameworks more effectively
•   handle RWD neatly
•   have less cluttered code




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
workflow
📁    css

📁    images

📁    scripts

📄    index.html




@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
workflow
📁    css

📁    images

📁    sass

📁    scripts

📄    index.html




@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
workflow
📁    css

📁    images

📁    sass

       📄      style.scss
     scripts
📁
📄    index.html



@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
workflow


       📄                             ⚙                📄
style.scss                        processor   style.css




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS    #REFRESHDUBLIN   18 JULY 2012
workflow
📁    css

       📄      style.css
📁    images
📁    sass

       📄      style.scss
📁    scripts

📄    index.html

@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
all you do is...
•   make a .scss file
•   write to it, just like normal CSS
•   translate it to a CSS file/folder:
•   sass --watch style.scss:style.css
•   sass --watch stylesheets/ ↵
    sass:stylesheets/compiled
•   and any changes you make to your SCSS
    file(s) will be complied to your CSS file(s).


    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
Y U NO




                USE LESS.JS?
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
Install Ruby rubyinstaller.org
$ sudo gem install sass
$ sass --watch style.scss:style.css




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
http://incident57.com/codekit/




@IRISHSTU   AN INTRODUCTION TO SASSY CSS                     #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
$variables
“   variables allow you to use the
    same value in multiple places, as
    well as perform basic maths and
    functions.




      @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
why variables rock
Change one variable and you change
it everywhere. Save hours of search &
replacing. Experiment with small
changes in margins & gutters. Reskin
with different colours...



  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
$variables
•    begin with a dollar sign $
•    assign a value with a colon separator :
•    end with semi-colon ;

    $red           :     #ff0000;
    $font          :     "Open Sans", Arial, Sans-Serif;
    $margin        :     16px;
    $column        :     40px;
    $type          :     1em;




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS       #REFRESHDUBLIN   18 JULY 2012
$primarycolor   :   red
                                                     $mainfont       :   “Open Sans...
                                                     $basetypesize   :   1em




$variables
                                                     $margin         :   16px




•    use instead of a value
                                                                                   SCSS
    h1    {
        color: $primarycolor;
        font-family: $mainfont;
        font-size: $basetypesize;
        margin: 0 0 $margin 0;
    }



    h1 {
      color: red;
      font-family: "Open Sans", Arial, Sans-Serif;
      font-size: 1em;
      margin: 0 0 16px 0;
    }
                                                                                    CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS               #REFRESHDUBLIN      18 JULY 2012
operations
•   maths: + - / *
•   color: darken, lighten, saturation, opacity
•   http://sass-lang.com/docs/yardoc/Sass/
    Script/Functions.html




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
$primarycolor : red
                                               $column       : 40px
                                               $margin       : 16px




operations
                                                                          SCSS
.island    {
    background: darken($primarycolor,10%);
    width: $column*4;
    margin: $margin*2 $margin/2 $margin+20 $margin;
    padding: $margin*0.25;
}



.island {
  background: #cc0000;
  width: 160px;
  margin: 32px 8px 36px 16px;
  padding: 4px;
}
                                                                           CSS




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS             #REFRESHDUBLIN   18 JULY 2012
$basetypesize : 1em




escaping
•    wrap with #{ }
•    useful for paths

                                                                              SCSS
    p {
      font: #{$basetypesize}/#{$basetypesize*1.5} $mainfont;
      }



    p {
      font: 1em/1.5em "Open Sans", Arial, Sans-Serif;
      }
                                                                               CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS             #REFRESHDUBLIN   18 JULY 2012
$margin         : 16px




negatives
•    minus symbols
•    -64px -32px 0 16px
•    top: -96px; right , left are 0; bottom is 16px
                                                                                SCSS
    .moveup    {
        margin:-$margin*4 -$margin*2 0 $margin;
    }



    .moveup {
      margin: -96px 0 16px;
    }
                                                                                 CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS               #REFRESHDUBLIN   18 JULY 2012
$margin         : 16px




negatives
•    wrap in brackets
•    (-$variable*value)

                                                                                    SCSS
    .moveup    {
        margin:(-$margin*4) (-$margin*2) 0 $margin;
    }



    .moveup {
      margin: -64px -32px 0 16px;
    }
                                                                                     CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS                   #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
nesting
“   Sass avoids repetition by
    nesting selectors within one
    another. The same thing works
    with properties. www.sass-lang.com




      @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
why nesting rocks
Write a hell of a lot less CSS. Avoid
repetion. Use indentation to quickly
scan and see relationships. Use
ampersands for awesomeness.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
write html as normal

                                                                     HTML
  <nav>
   <ul>
      <li><a          href="#">Home</a></li>
      <li><a          href="#">About</a></li>
      <li><a          href="#">Services</a></li>
      <li><a          href="#">Contact Us</a></li>
   </ul>
</nav>




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS        #REFRESHDUBLIN   18 JULY 2012
$mainfont    : “Open Sans...
                                                      $margin      : 16px




nest & indent
                                                                                 SCSS
nav    {
    font-family: $mainfont;

    ul    {
        margin: 0;
        padding: 0;

        li {
            list-style: none;

                  a {
                      background: #222;
                      color: #fff;
                      display: block;
                      float: left;
                      padding: $margin $margin*1.5;
                      text-decoration: none;
                  }    
            }
      }
}




    @IRISHSTU    AN INTRODUCTION TO SASSY CSS                #REFRESHDUBLIN   18 JULY 2012
$mainfont    : “Open Sans...
                                                 $margin      : 16px




nest & indent
                                                                             CSS
nav {
  font-family: "Open Sans", Arial, Sans-Serif;
}
  
nav ul {
  margin: 0;
  padding: 0;
}

nav ul li {
   list-style: none;
}

nav ul li a {
   background: #222;
   border-right: 1px solid #666;
   color: #fff;
   display: block;
   float: left;
   padding: 16px 24px;
   text-decoration: none;
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS               #REFRESHDUBLIN   18 JULY 2012
selectors
                                                                SCSS
em    {
    font:    {
        family: Georgia, Serif;
        style: normal;
        weight: bold;
        variant: small-caps;
    }
}



em {
  font-family: Georgia, Serif;
  font-style: normal;
  font-weight: bold;
  font-variant: small-caps;
}
                                                                 CSS




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
&
@IRISHSTU
                              ampersand




            AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
$primarycolor : #993333




& ampersand
•     pulls the parent selector into the &
                                                                                   SCSS
    #fancybox {
        li a.fancy {
            &:link    { color: $primarycolor; }
            &:visited { color: darken($primarycolor,20%); }
            &:hover   { color: lighten($primarycolor,10%); }
        }
    }



    #fancybox li a.fancy:link    { color: #993333; }
    #fancybox li a.fancy:visited { color: #4d1919; }
    #fancybox li a.fancy:hover   { color: #bf4040; }
                                                                                    CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS                  #REFRESHDUBLIN   18 JULY 2012
$primarycolor : #993333




ampersand &
•     prepends before parent selector
                                                                                      SCSS
    #fancybox {
        li a.fancy {
            &:link  { color: $primarycolor; }
            &:hover { color: lighten($primarycolor,10%); }
            
            body#checkout & { border:1px solid $primarycolor; }
        }
    }



    #fancybox li a.fancy:link           { color: #993333; }
    #fancybox li a.fancy:hover          { color: #bf4040; }
    body#checkout #fancybox li a.fancy  { border: 1px solid #993333; }
                                                                                       CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS                     #REFRESHDUBLIN   18 JULY 2012
ampersand &
•    use with HTML body classes
                                                                    SCSS
    #browserwars    {
        border: 1px solid red;
        
        .ie8 &, .ie9 & {
            border: 1px solid blue;
        }
        .ie10 & {
            border: 1px solid green;
        }
    }




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
ampersand &
•    use with HTML body classes
                                                                     CSS
    #browserwars {
      border: 1px solid red;
    }
    .ie8 #browserwars, .ie9 #browserwars {
        border: 1px solid blue;
    }
    .ie10 #browserwars {
        border: 1px solid green;
    }




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
$size : 16px




ampersand &
•    use with HTML body classes
                                                                             SCSS
    $size :16px;

    h1    {
        font: {
            family: Arial, sans-serif;  
            size: $size;
        }
        .wf-active &    {
            font: {
                family: "proxima-nova-extra-condensed", Arial, sans-serif;  
                size: $size*1.5;
            }
        }
    }



     @IRISHSTU   AN INTRODUCTION TO SASSY CSS            #REFRESHDUBLIN   18 JULY 2012
$size : 16px




ampersand &
•    use with HTML body classes
                                                                              CSS
    h1 {
        font-family: Arial, sans-serif;
        font-size: 16px;
    }
      
    .wf-active h1 {
        font-family: "proxima-nova-extra-condensed", Arial, sans-serif;
        font-size: 24px;
    }




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS            #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@mixins
“   mixins allow you to re-use whole
    chunks of CSS, properties or
    selectors. You can even give
    them arguments. www.sass-lang.com




      @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
why mixins rock
Reduce massive chunks of CSS into
reusable includes that you can use
over and over again.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
http://compass-style.org/




@IRISHSTU   AN INTRODUCTION TO SASSY CSS                    #REFRESHDUBLIN   18 JULY 2012
@mixin
•    begin with @mixin
•    give it a name
•    add your $variable(s)
•    give (an) optional default value(s)

    @mixin roundcorner ($radius: 4px)    {
        -webkit-border-radius: $radius;
        -moz-border-radius: $radius;
        border-radius: $radius;
    }



     @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@mixin
•    call it with @include
                                                                    SCSS
    .fancybox    {
        width: 100px;
        @include roundcorner(10);
    }



    .fancybox {
      width: 100px;
      -webkit-border-radius: 10px;
      -moz-border-radius: 10px;
      border-radius: 10px;
    }
                                                                     CSS




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
image replace
@mixin hidetext    {
    text-indent: 100%;
    white-space: nowrap;
    overflow: hidden;
}

.logo    {
    background: url(images/logo.png) no-repeat;
    @include hidetext;
    width: 200px;
    height: 80px;
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
boxshadow
@mixin boxshadow ($horz, $vert, $blur, $spread, $color)    {
    -webkit-box-shadow: #{$horz}px #{$vert}px #{$blur}px #{$spread}px $color;
    -moz-box-shadow: #{$horz} px #{$vert}px #{$blur}px #{$spread}px $color;
    box-shadow: #{$horz}px #{$vert}px #{$blur}px #{$spread}px $color;
}

@include boxshadow (2,2,2,0,rgba(0,0,0,0.5));




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS                  #REFRESHDUBLIN   18 JULY 2012
transitions
@mixin transanim ($time)    {
    -webkit-transition: all #{$time}s ease-in-out;
    -moz-transition: all #{$time} s ease-in-out;
    -o-transition: all #{$time}s ease-in-out;
    -ms-transition: all #{$time}s ease-in-out;
    transition: all all #{$time}s ease-in-out;
}

* {
   @include transanim(0.5);
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
$grid       : 20px
                                            $lineheight : 1em



type
@mixin type ($size, $lineheight, $marginbottom: 1 1.5 1)    {
    font-size: $grid*$size;
    font-size: $grid*$size / 16px + rem;
    line-height: $grid*$lineheight;
    line-height: $grid*$lineheight / 16px + rem;
    margin:0 0 $grid*$marginbottom 0;
}

h1    {
  @include type
  (1.75, 2, 1);
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS      #REFRESHDUBLIN   18 JULY 2012
$grid       : 20px
                                            $lineheight : 1em



type
                                                                    CSS
h1 {
  font-size: 35px;
  font-size: 2.188rem;
  line-height: 40px;
  line-height: 2.5rem;
  margin: 0 0 20px 0;
  }




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS      #REFRESHDUBLIN   18 JULY 2012
@each
                                                                         SCSS
$social: twitter facebook linkedin;

@mixin social-icons {
   @each $icon in $social {
      .social-#{$icon} {
         background: url("images/#{$icon}.png") no-repeat;
      }
   }
}
 
.social {
  @include social-icons;
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS            #REFRESHDUBLIN   18 JULY 2012
it’s a loop!
                                                                           CSS
.social .social-twitter {
  background: url("images/twitter.png") no-repeat;
}
  
.social .social-facebook {
  background: url("images/facebook.png") no-repeat;
}
  
.social .social-linkedin {
  background: url("images/linkedin.png") no-repeat;
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS             #REFRESHDUBLIN   18 JULY 2012
retina
                                                                               SCSS
@mixin bgretina    ($source, $format )    {
    background:    {
        image: url("#{$source}.#{$format}");
        size: cover;
        repeat: no-repeat;
    }
    @media screen and (-webkit-min-device-pixel-ratio: 2)    {
        background:    {
            image: url("#{$source}@2x.#{$format}");
        }
    }
}

#responsivetest    {
    width: 400px;
    height: 400px;
    @include bgretina(bgimage,png)
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS                  #REFRESHDUBLIN   18 JULY 2012
retina
                                                                          CSS
#responsivetest {
  width: 400px;
  height: 400px;
  background-image: url("bgimage.png");
  background-size: cover;
  background-repeat: no-repeat; }
  @media screen and (-webkit-min-device-pixel-ratio: 2) {
    #responsivetest {
      background-image: url("bgimage@2x.png"); }
  }




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS            #REFRESHDUBLIN   18 JULY 2012
ampersand &
•     make it a mixin to reuse
                                                                                   SCSS
    @mixin webfonts    ($fallback, $shinytype, $size)    {
        font: {
            family: #{$fallback};
            size: $size;
        }
            
        .wf-active &    {
            font: {
                family: "#{$shinytype}", #{$fallback};  
                size: $size*1.5;
            }
        }
    }

    h1    {
    @include webfonts("Arial, sans-serif", "proxima-nova-extra-condensed", 16px);
    }




     @IRISHSTU   AN INTRODUCTION TO SASSY CSS                  #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@media
“   @media directives in Sass
    behave just like they do in plain
    CSS, with one extra capability:
    they can be nested in CSS rules.
    www.sass-lang.com




      @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
why
media queries rock
Make responsive layouts. Associate
media queries more closley with the
element you are changeing.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@media
•   begin with @media
•   write media queries as normal
•   if it appears within a rule, it will ‘bubble up’
    and put the selectors within the rule.
•   media queries can be nested
•   combined with the and rule




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@media
                                                                SCSS
.sidebar {
  float: right;
  width: 300px;
  @media screen and (max-width: 480px) {
      float: none;
    width: 100%;
  }
}



.sidebar {
  float: right;
  width: 300px;
}
@media screen and (max-width: 480px) {
    .sidebar {
      float: none;
      width: 100%;
    }
}
                                                                 CSS



 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
1
                                    2
               #logo                                  #menu



                                                                                 4
                             3

             #leftnav



                                                     #content




               5
                                           #footer




@IRISHSTU   AN INTRODUCTION TO SASSY CSS                        #REFRESHDUBLIN   18 JULY 2012
2              #menu


                             1              #logo




                                           #content
                             4




                             3             #leftnav




                             5             #footer




@IRISHSTU   AN INTRODUCTION TO SASSY CSS              #REFRESHDUBLIN   18 JULY 2012
@media
                                                                SCSS
@mixin boxit ($dir) {
    display:box;
    display:-moz-box;
    display:-webkit-box;
    box-orient:$dir;
    -moz-box-orient:$dir;
    -webkit-box-orient:$dir;
}

@mixin boxnum($num: 1) {
    box-ordinal-group: #{$num};
    -moz-box-ordinal-group: #{$num};
    -webkit-box-ordinal-group: #{$num};
}




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@media
                                                                               SCSS
@media screen and (max-width: 480px) {

      #wrapper    {
          width: 100%;
          @include boxit(vertical);
 
        #logo      {          @include    boxnum(2);   }
        #menu      {          @include    boxnum(1);   }
        #content   {          @include    boxnum(3);   }
        #leftnav   {          @include    boxnum(4);   }
        #footer    {          @include    boxnum(5);   }
    }
}




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS               #REFRESHDUBLIN   18 JULY 2012
2              #menu     1

                             1              #logo     2




                                           #content
                             4                        3




                             3             #leftnav   4



                             5             #footer    5



@IRISHSTU   AN INTRODUCTION TO SASSY CSS                  #REFRESHDUBLIN   18 JULY 2012
3.2
@IRISHSTU
                            coming soon



            AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@media
You can’t use this yet - watch https://github.com/nex3/sass/



•   variables in queries
•   Sass 3.2 alpha
•   other cool stuff




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS         #REFRESHDUBLIN   18 JULY 2012
@media
You can’t use this yet - watch https://github.com/nex3/sass/
                                                                                                           SCSS
 @mixin respond-to($media) {
   @if $media == handhelds {
     @media only screen and (max-width: 320px) { @content; }
   }
   @else if $media == medium-screens {
     @media only screen and (min-width: 321px) and (max-width: 1024px) { @content; }
   }
   @else if $media == wide-screens {
     @media only screen and (min-width: 1024px) { @content; }
   }
 }

 .profile-pic {
   float: left;
   width: 250px;
   @include respond-to(handhelds) { width: 100% ;}
   @include respond-to(medium-screens) { width: 125px; }
   @include respond-to(wide-screens) { float: none; }
 }


 http://thesassway.com/intermediate/responsive-web-design-part-2#the_future_of_media_queries_in_sass


   @IRISHSTU    AN INTRODUCTION TO SASSY CSS                                           #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
_partials
“   partials are snippets of scss
    that are saved into files meant
    to be imported. They begin
    with an underscore and don’t
    get compiled.




      @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
why partials rock
Include files for CSS. Make your files
more managable by breaking them
into discreet external modules.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
_partials
•   filename starts with an underscore
•   e.g. “_grid.scss”
•   import it into your .scss file
•   @import "grid";
•   save on HTTP requests
•   better structure




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
workflow

                   📄                                 ⚙                 📄
         style.scss                               processor    style.css



     📄              📄                📄
_reset.scss     _grid.scss       _type.scss




              @IRISHSTU      AN INTRODUCTION TO SASSY CSS     #REFRESHDUBLIN   18 JULY 2012
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
examples
•   Separate partials for:

•   grids, typography, colours, forms, tables
•   mixins & variables
•   different post types for blogs
•   adverts
•   media queries
•   site sub-sections


    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@extend
“   The @extend directive (tells) Sass
    that one selector should inherit
    the styles of another selector.
    http://nex-3.com/posts/99-selector-inheritance-the-easy-way-introducing-extend




       @IRISHSTU   AN INTRODUCTION TO SASSY CSS                  #REFRESHDUBLIN   18 JULY 2012
why extend rocks
Lets you add styles from one selector
to another, as well as its own styles.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@extend
•   nest @extend .classname;
•   goes inside another class
•   don’t have to use multiple classes
•   association is in CSS not HTML




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@extend
                                                                SCSS
.error {
  border: 1px #f00;
  background: #fdd;
}

.badError {
  @extend .error;
  border-width: 3px;
}



.error, .badError {
  border: 1px #f00;
  background: #fdd;
}

.badError {
  border-width: 3px;
}
                                                                 CSS




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
gotchas!
A few things to watch out for when
working with SCSS.




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
/facepalm
•   make sure you’re running your compiler
•   make sure it’s not CSS
•   watch out for escaping #{values}
•   be aware of inheritance
•   when you go back to CSS, don’t forget your
    inheritance




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
codekit




@IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
TOPICS


•   What’s Sass/SCSS?
•   Installing Sass
•   Variables
•   Nesting
•   Mixins
•   Media Queries
•   Partials
•   Inheritance
•   Gotchas
•   Links




    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
useful links




 @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
learn more
•   http://sass-lang.com/
•   http://www.youtube.com/watch?
    v=fbVD32w1oTo
•   https://twitter.com/teamsassdesign
•   https://twitter.com/scottkellum
•   http://www.slideshare.net/ginader/sass-
    compass-and-the-new-tools-open-web-
    camp-iv



    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
learn more
•   http://incident57.com/codekit/
•   http://compass-style.org/
•   http://thesassway.com/projects/sass-
    twitter-bootstrap
•   http://foundation.zurb.com/
•   http://zengrids.com/
•   http://jaredhardy.com/sassy-buttons/



    @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012
thank you!
feedback, comments, links?

     @irishstu




  @IRISHSTU   AN INTRODUCTION TO SASSY CSS   #REFRESHDUBLIN   18 JULY 2012

Weitere ähnliche Inhalte

Ähnlich wie An Introduction to Sassy CSS

Pacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASSPacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASSSteve Krueger
 
Using Sass - Building on CSS
Using Sass - Building on CSSUsing Sass - Building on CSS
Using Sass - Building on CSSSayanee Basu
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockMarco Pinheiro
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESSItai Koren
 
Save time by using sass to develop css
Save time by using sass to develop cssSave time by using sass to develop css
Save time by using sass to develop cssBill Chea
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quickBilly Shih
 
From CSS to Sass in WordPress
From CSS to Sass in WordPressFrom CSS to Sass in WordPress
From CSS to Sass in WordPressJames Steinbach
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassLucien Lee
 
Using SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar ZikUsing SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar ZikMiriam Schwab
 
Styling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projectsStyling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projectsAppsilon Data Science
 
CSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y tryingCSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y tryingJames Cryer
 
CSS Workflow. Pre & Post
CSS Workflow. Pre & PostCSS Workflow. Pre & Post
CSS Workflow. Pre & PostAnton Dosov
 

Ähnlich wie An Introduction to Sassy CSS (20)

CSS Extenders
CSS ExtendersCSS Extenders
CSS Extenders
 
Pacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASSPacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASS
 
Using Sass - Building on CSS
Using Sass - Building on CSSUsing Sass - Building on CSS
Using Sass - Building on CSS
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, Greensock
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
 
Css frameworks
Css frameworksCss frameworks
Css frameworks
 
Save time by using sass to develop css
Save time by using sass to develop cssSave time by using sass to develop css
Save time by using sass to develop css
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quick
 
From CSS to Sass in WordPress
From CSS to Sass in WordPressFrom CSS to Sass in WordPress
From CSS to Sass in WordPress
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
Sass_Cubet seminar
Sass_Cubet seminarSass_Cubet seminar
Sass_Cubet seminar
 
Preprocessor CSS: SASS
Preprocessor CSS: SASSPreprocessor CSS: SASS
Preprocessor CSS: SASS
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Why less?
Why less?Why less?
Why less?
 
Using SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar ZikUsing SASS in the WordPress environment - Ran Bar Zik
Using SASS in the WordPress environment - Ran Bar Zik
 
Styling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projectsStyling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projects
 
Less css
Less cssLess css
Less css
 
CSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y tryingCSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y trying
 
CSS Workflow. Pre & Post
CSS Workflow. Pre & PostCSS Workflow. Pre & Post
CSS Workflow. Pre & Post
 

Kürzlich hochgeladen

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Kürzlich hochgeladen (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

An Introduction to Sassy CSS

  • 1. An Introduction to Sassy CSS Stewart Curry @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 2. Who is This Guy? Web Designer for 15 years or so Table-based layouts & spacer gifs CSS changed all that SCSS is CSS only better woop.ie - iteration, modules, themes, templates @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 3. past simple @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 4. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 5. now complicated @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 6. 💬 @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 7. design everywhere @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 8.      📱  💻 @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 9. SASS MAKES CSS FUN AGAIN www.sass-lang.com Basically, CSS made flexible & awesome by adding in cool features. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 10. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 11. There Will be Code @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 12. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 13. Sass Style with attitude “ Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin. www.sass-lang.com @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 14. it looks like CSS $blue: #3bbfce; $margin: 16px; .content-navigation {   border-color: $blue;   color: darken($blue, 9%); } .border {   padding: $margin / 2;   margin: $margin / 2;   border-color: $blue; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 15. it looks like CSS but • it’s neater • it’s faster to write • it allows for more experimentation • it’s more flexible • it’s more manageable • it’s got variables! @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 16. so you can • experiment more • make global changes quickly • make reusable modules • use frameworks more effectively • handle RWD neatly • have less cluttered code @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 17. workflow 📁 css 📁 images 📁 scripts 📄 index.html @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 18. workflow 📁 css 📁 images 📁 sass 📁 scripts 📄 index.html @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 19. workflow 📁 css 📁 images 📁 sass 📄 style.scss scripts 📁 📄 index.html @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 20. workflow 📄 ⚙ 📄 style.scss processor style.css @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 21. workflow 📁 css 📄 style.css 📁 images 📁 sass 📄 style.scss 📁 scripts 📄 index.html @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 22. all you do is... • make a .scss file • write to it, just like normal CSS • translate it to a CSS file/folder: • sass --watch style.scss:style.css • sass --watch stylesheets/ ↵ sass:stylesheets/compiled • and any changes you make to your SCSS file(s) will be complied to your CSS file(s). @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 23. Y U NO USE LESS.JS? @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 24. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 25. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 26. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 27. Install Ruby rubyinstaller.org $ sudo gem install sass $ sass --watch style.scss:style.css @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 28. http://incident57.com/codekit/ @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 29. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 30. $variables “ variables allow you to use the same value in multiple places, as well as perform basic maths and functions. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 31. why variables rock Change one variable and you change it everywhere. Save hours of search & replacing. Experiment with small changes in margins & gutters. Reskin with different colours... @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 32. $variables • begin with a dollar sign $ • assign a value with a colon separator : • end with semi-colon ; $red    :  #ff0000; $font    :  "Open Sans", Arial, Sans-Serif; $margin  :  16px; $column  :  40px; $type  :  1em; @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 33. $primarycolor : red $mainfont : “Open Sans... $basetypesize : 1em $variables $margin : 16px • use instead of a value SCSS h1    {     color: $primarycolor;     font-family: $mainfont;     font-size: $basetypesize;     margin: 0 0 $margin 0; } h1 {   color: red;   font-family: "Open Sans", Arial, Sans-Serif;   font-size: 1em;   margin: 0 0 16px 0; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 34. operations • maths: + - / * • color: darken, lighten, saturation, opacity • http://sass-lang.com/docs/yardoc/Sass/ Script/Functions.html @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 35. $primarycolor : red $column : 40px $margin : 16px operations SCSS .island    {     background: darken($primarycolor,10%);     width: $column*4;     margin: $margin*2 $margin/2 $margin+20 $margin;     padding: $margin*0.25; } .island {   background: #cc0000;   width: 160px;   margin: 32px 8px 36px 16px;   padding: 4px; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 36. $basetypesize : 1em escaping • wrap with #{ } • useful for paths SCSS p {   font: #{$basetypesize}/#{$basetypesize*1.5} $mainfont; } p {   font: 1em/1.5em "Open Sans", Arial, Sans-Serif;   } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 37. $margin : 16px negatives • minus symbols • -64px -32px 0 16px • top: -96px; right , left are 0; bottom is 16px SCSS .moveup    {     margin:-$margin*4 -$margin*2 0 $margin; } .moveup {   margin: -96px 0 16px; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 38. $margin : 16px negatives • wrap in brackets • (-$variable*value) SCSS .moveup    {     margin:(-$margin*4) (-$margin*2) 0 $margin; } .moveup {   margin: -64px -32px 0 16px; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 39. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 40. nesting “ Sass avoids repetition by nesting selectors within one another. The same thing works with properties. www.sass-lang.com @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 41. why nesting rocks Write a hell of a lot less CSS. Avoid repetion. Use indentation to quickly scan and see relationships. Use ampersands for awesomeness. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 42. write html as normal HTML <nav>    <ul>       <li><a href="#">Home</a></li>       <li><a href="#">About</a></li>       <li><a href="#">Services</a></li>       <li><a href="#">Contact Us</a></li>    </ul> </nav> @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 43. $mainfont : “Open Sans... $margin : 16px nest & indent SCSS nav    {     font-family: $mainfont;     ul    {         margin: 0;         padding: 0;         li {             list-style: none;             a {                 background: #222;                 color: #fff;                 display: block;                 float: left;                 padding: $margin $margin*1.5;                 text-decoration: none;             }             }     } } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 44. $mainfont : “Open Sans... $margin : 16px nest & indent CSS nav {   font-family: "Open Sans", Arial, Sans-Serif; }    nav ul {   margin: 0;   padding: 0; } nav ul li {    list-style: none; } nav ul li a {    background: #222;    border-right: 1px solid #666;    color: #fff;    display: block;    float: left;    padding: 16px 24px;    text-decoration: none; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 45. selectors SCSS em    {     font:    {         family: Georgia, Serif;         style: normal;         weight: bold;         variant: small-caps;     } } em {   font-family: Georgia, Serif;   font-style: normal;   font-weight: bold;   font-variant: small-caps; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 46. & @IRISHSTU ampersand AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 47. $primarycolor : #993333 & ampersand • pulls the parent selector into the & SCSS #fancybox {     li a.fancy {         &:link    { color: $primarycolor; }         &:visited { color: darken($primarycolor,20%); }         &:hover   { color: lighten($primarycolor,10%); }     } } #fancybox li a.fancy:link    { color: #993333; } #fancybox li a.fancy:visited { color: #4d1919; } #fancybox li a.fancy:hover   { color: #bf4040; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 48. $primarycolor : #993333 ampersand & • prepends before parent selector SCSS #fancybox {     li a.fancy {         &:link  { color: $primarycolor; }         &:hover { color: lighten($primarycolor,10%); }                  body#checkout & { border:1px solid $primarycolor; }     } } #fancybox li a.fancy:link           { color: #993333; } #fancybox li a.fancy:hover          { color: #bf4040; } body#checkout #fancybox li a.fancy  { border: 1px solid #993333; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 49. ampersand & • use with HTML body classes SCSS #browserwars    {     border: 1px solid red;          .ie8 &, .ie9 & {         border: 1px solid blue;     }     .ie10 & {         border: 1px solid green;     } } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 50. ampersand & • use with HTML body classes CSS #browserwars {   border: 1px solid red; } .ie8 #browserwars, .ie9 #browserwars {     border: 1px solid blue; } .ie10 #browserwars {     border: 1px solid green; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 51. $size : 16px ampersand & • use with HTML body classes SCSS $size :16px; h1    {     font: {         family: Arial, sans-serif;           size: $size;     }     .wf-active &    {         font: {             family: "proxima-nova-extra-condensed", Arial, sans-serif;               size: $size*1.5;         }     } } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 52. $size : 16px ampersand & • use with HTML body classes CSS h1 {     font-family: Arial, sans-serif;     font-size: 16px; }    .wf-active h1 {     font-family: "proxima-nova-extra-condensed", Arial, sans-serif;     font-size: 24px; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 53. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 54. @mixins “ mixins allow you to re-use whole chunks of CSS, properties or selectors. You can even give them arguments. www.sass-lang.com @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 55. why mixins rock Reduce massive chunks of CSS into reusable includes that you can use over and over again. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 56. http://compass-style.org/ @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 57. @mixin • begin with @mixin • give it a name • add your $variable(s) • give (an) optional default value(s) @mixin roundcorner ($radius: 4px)    {     -webkit-border-radius: $radius;     -moz-border-radius: $radius;     border-radius: $radius; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 58. @mixin • call it with @include SCSS .fancybox    {     width: 100px;     @include roundcorner(10); } .fancybox {   width: 100px;   -webkit-border-radius: 10px;   -moz-border-radius: 10px;   border-radius: 10px; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 59. image replace @mixin hidetext    {     text-indent: 100%;     white-space: nowrap;     overflow: hidden; } .logo    {     background: url(images/logo.png) no-repeat;     @include hidetext; width: 200px; height: 80px; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 60. boxshadow @mixin boxshadow ($horz, $vert, $blur, $spread, $color)    {     -webkit-box-shadow: #{$horz}px #{$vert}px #{$blur}px #{$spread}px $color;     -moz-box-shadow: #{$horz} px #{$vert}px #{$blur}px #{$spread}px $color;     box-shadow: #{$horz}px #{$vert}px #{$blur}px #{$spread}px $color; } @include boxshadow (2,2,2,0,rgba(0,0,0,0.5)); @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 61. transitions @mixin transanim ($time)    {     -webkit-transition: all #{$time}s ease-in-out;     -moz-transition: all #{$time} s ease-in-out;     -o-transition: all #{$time}s ease-in-out;     -ms-transition: all #{$time}s ease-in-out;     transition: all all #{$time}s ease-in-out; } * {    @include transanim(0.5); } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 62. $grid : 20px $lineheight : 1em type @mixin type ($size, $lineheight, $marginbottom: 1 1.5 1)    {     font-size: $grid*$size;     font-size: $grid*$size / 16px + rem;     line-height: $grid*$lineheight;     line-height: $grid*$lineheight / 16px + rem;     margin:0 0 $grid*$marginbottom 0; } h1    {   @include type   (1.75, 2, 1); } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 63. $grid : 20px $lineheight : 1em type CSS h1 {   font-size: 35px;   font-size: 2.188rem;   line-height: 40px;   line-height: 2.5rem;   margin: 0 0 20px 0;   } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 64. @each SCSS $social: twitter facebook linkedin; @mixin social-icons {    @each $icon in $social {       .social-#{$icon} {          background: url("images/#{$icon}.png") no-repeat;       }    } }   .social {   @include social-icons; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 65. it’s a loop! CSS .social .social-twitter {   background: url("images/twitter.png") no-repeat; }    .social .social-facebook {   background: url("images/facebook.png") no-repeat; }    .social .social-linkedin {   background: url("images/linkedin.png") no-repeat; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 66. retina SCSS @mixin bgretina    ($source, $format )    {     background:    {         image: url("#{$source}.#{$format}");         size: cover;         repeat: no-repeat;     }     @media screen and (-webkit-min-device-pixel-ratio: 2)    {         background:    {             image: url("#{$source}@2x.#{$format}");         }     } } #responsivetest    {     width: 400px;     height: 400px;     @include bgretina(bgimage,png) } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 67. retina CSS #responsivetest {   width: 400px;   height: 400px;   background-image: url("bgimage.png");   background-size: cover;   background-repeat: no-repeat; }   @media screen and (-webkit-min-device-pixel-ratio: 2) {     #responsivetest {       background-image: url("bgimage@2x.png"); }   } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 68. ampersand & • make it a mixin to reuse SCSS @mixin webfonts    ($fallback, $shinytype, $size)    {     font: {         family: #{$fallback};         size: $size;     }              .wf-active &    {         font: {             family: "#{$shinytype}", #{$fallback};               size: $size*1.5;         }     } } h1    { @include webfonts("Arial, sans-serif", "proxima-nova-extra-condensed", 16px); } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 69. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 70. @media “ @media directives in Sass behave just like they do in plain CSS, with one extra capability: they can be nested in CSS rules. www.sass-lang.com @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 71. why media queries rock Make responsive layouts. Associate media queries more closley with the element you are changeing. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 72. @media • begin with @media • write media queries as normal • if it appears within a rule, it will ‘bubble up’ and put the selectors within the rule. • media queries can be nested • combined with the and rule @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 73. @media SCSS .sidebar {   float: right;   width: 300px;   @media screen and (max-width: 480px) {       float: none;     width: 100%;   } } .sidebar {   float: right;   width: 300px; } @media screen and (max-width: 480px) {     .sidebar {       float: none;       width: 100%;     } } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 74. 1 2 #logo #menu 4 3 #leftnav #content 5 #footer @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 75. 2 #menu 1 #logo #content 4 3 #leftnav 5 #footer @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 76. @media SCSS @mixin boxit ($dir) {     display:box;     display:-moz-box;     display:-webkit-box;     box-orient:$dir;     -moz-box-orient:$dir;     -webkit-box-orient:$dir; } @mixin boxnum($num: 1) {     box-ordinal-group: #{$num};     -moz-box-ordinal-group: #{$num};     -webkit-box-ordinal-group: #{$num}; } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 77. @media SCSS @media screen and (max-width: 480px) {     #wrapper    {         width: 100%;         @include boxit(vertical);           #logo      { @include boxnum(2); }         #menu      { @include boxnum(1); } #content   { @include boxnum(3); }         #leftnav   { @include boxnum(4); }         #footer    { @include boxnum(5); }     } } @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 78. 2 #menu 1 1 #logo 2 #content 4 3 3 #leftnav 4 5 #footer 5 @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 79. 3.2 @IRISHSTU coming soon AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 80. @media You can’t use this yet - watch https://github.com/nex3/sass/ • variables in queries • Sass 3.2 alpha • other cool stuff @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 81. @media You can’t use this yet - watch https://github.com/nex3/sass/ SCSS @mixin respond-to($media) {   @if $media == handhelds {     @media only screen and (max-width: 320px) { @content; }   }   @else if $media == medium-screens {     @media only screen and (min-width: 321px) and (max-width: 1024px) { @content; }   }   @else if $media == wide-screens {     @media only screen and (min-width: 1024px) { @content; }   } } .profile-pic {   float: left;   width: 250px;   @include respond-to(handhelds) { width: 100% ;}   @include respond-to(medium-screens) { width: 125px; }   @include respond-to(wide-screens) { float: none; } } http://thesassway.com/intermediate/responsive-web-design-part-2#the_future_of_media_queries_in_sass @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 82. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 83. _partials “ partials are snippets of scss that are saved into files meant to be imported. They begin with an underscore and don’t get compiled. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 84. why partials rock Include files for CSS. Make your files more managable by breaking them into discreet external modules. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 85. _partials • filename starts with an underscore • e.g. “_grid.scss” • import it into your .scss file • @import "grid"; • save on HTTP requests • better structure @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 86. workflow 📄 ⚙ 📄 style.scss processor style.css 📄 📄 📄 _reset.scss _grid.scss _type.scss @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 87. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 88. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 89. examples • Separate partials for: • grids, typography, colours, forms, tables • mixins & variables • different post types for blogs • adverts • media queries • site sub-sections @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 90. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 91. @extend “ The @extend directive (tells) Sass that one selector should inherit the styles of another selector. http://nex-3.com/posts/99-selector-inheritance-the-easy-way-introducing-extend @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 92. why extend rocks Lets you add styles from one selector to another, as well as its own styles. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 93. @extend • nest @extend .classname; • goes inside another class • don’t have to use multiple classes • association is in CSS not HTML @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 94. @extend SCSS .error {   border: 1px #f00;   background: #fdd; } .badError {   @extend .error;   border-width: 3px; } .error, .badError {   border: 1px #f00;   background: #fdd; } .badError {   border-width: 3px; } CSS @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 95. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 96. gotchas! A few things to watch out for when working with SCSS. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 97. @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 98. /facepalm • make sure you’re running your compiler • make sure it’s not CSS • watch out for escaping #{values} • be aware of inheritance • when you go back to CSS, don’t forget your inheritance @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 99. codekit @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 100. TOPICS • What’s Sass/SCSS? • Installing Sass • Variables • Nesting • Mixins • Media Queries • Partials • Inheritance • Gotchas • Links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 101. useful links @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 102. learn more • http://sass-lang.com/ • http://www.youtube.com/watch? v=fbVD32w1oTo • https://twitter.com/teamsassdesign • https://twitter.com/scottkellum • http://www.slideshare.net/ginader/sass- compass-and-the-new-tools-open-web- camp-iv @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 103. learn more • http://incident57.com/codekit/ • http://compass-style.org/ • http://thesassway.com/projects/sass- twitter-bootstrap • http://foundation.zurb.com/ • http://zengrids.com/ • http://jaredhardy.com/sassy-buttons/ @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012
  • 104. thank you! feedback, comments, links? @irishstu @IRISHSTU AN INTRODUCTION TO SASSY CSS #REFRESHDUBLIN 18 JULY 2012