Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why CSS Preprocessors Matter

jina
October 05, 2012

Why CSS Preprocessors Matter

ConvergeFL

jina

October 05, 2012
Tweet

More Decks by jina

Other Decks in Design

Transcript

  1. It used to be that designers made an object and

    walked away. Today the emphasis must shift to designing the entire life cycle.” ” —Paul Sa o
  2. I want my CSS file to be formatted pretty.” ”

    You should be compressing anyway.
  3. SCSS: Output: ul.items a { ... } ul.items:hover { ...

    } .ie-6 ul.items a { ... } ul.items a { ... &:hover { ... } .ie-6 & { ... } }
  4. SCSS: Output: ul.items { ... } @media print { ul.items

    { ... } } ul.items a { ... @media print { ... } }
  5. SCSS: Output: .sidebar { border: 1px solid #eee; border-top-color: #fff;

    border-left: 0; } .sidebar { border: 1px solid #eee { top-color: #fff; left: 0; } }
  6. SCSS: Output: body { color: #444; } footer { background:

    #444; } $text: #444; $bg: $text; body { color: $text; } footer { background: $bg; }
  7. SCSS: Output: .module { padding: 1em; } .info { padding:

    2em } @mixin spacing($s: 1em) { padding: $s; } .module { @include spacing; } .info { @include spacing(2em); }
  8. SCSS: Output: .message, .error { ... } .message.alert, .error.alert {

    ... } .error { ... } .message { ... &.alert { ... } } .error { ... @extend .message; }
  9. SCSS: Output: .module, .sidebar { color: #444; } .sidebar, .main

    { width: 240px; } .module { color: #444; } %grid-1 { width: 240px; } .sidebar { @extend .module; @extend %grid-1; } .main { @extend %grid-1; }
  10. $text: #444 color: lighten($text, 5%); color: darken($text, 5%); color: saturate($text,

    5%); color: adjust-hue($text, 180); color: grayscale($text); color: mix($text, #fff);
  11. SCSS: Output: /* Multiline comment; appears in output */ /*

    Multiline comment; appears in output */ // Singleline comment; // Hidden from output
  12. SCSS: Output: .i-red { background: url(red.png); } .i-blue { background:

    url(blue.png); } @each $c in red, blue { .i-#{$c} { background: url(#{$c}.png); } }
  13. SCSS: Output: .i-red { color: red; } .i-blue { color:

    blue; } @mixin i($color) { @if $color == red { color: red; } @else { color: blue; } } .i-red { @include i(red); } .i-blue { @include i; }
  14. // ---------------------------------------------- // 03. DEPENDENCIES // Variables/mixins/placeholders/etc // These don’t

    emit CSS on their own @import "dependencies/colour" @import "dependencies/measurements" @import "dependencies/typography" @import "dependencies/layout"
  15. // ---------------------------------- // 04. FOUNDATION // Plain semantic HTML //

    No classes/IDs are introduced yet. @import "foundation"
  16. // ------------------------------------- // 06. COMPONENTS // Reusable modules, components, etc.

    @import "components/forms" @import "components/buttons" @import "components/messaging" @import "components/pop-stripe"
  17. // POP STRIPE: https://gist.github.com/3141010 // Thanks goes to Eric A.

    Meyer // - $position: the starting position or angle of the gradient. // - $colors: a list of all the colors to be used. @function pop-stripe($position, $colors) $colors: if(type-of($colors) != 'list', compact($colors), $colors) $gradient: compact() $width: 100% / length($colors) @for $i from 1 through length($colors) $pop: nth($colors, $i) $new: $pop ($width * ($i - 1)), $pop ($width * $i) $gradient: join($gradient, $new, comma) @return linear-gradient($position, $gradient) .pop-stripe +background-image(pop-stripe(left, ($stripe-colors)))
  18. Web standards implementations of nesting, variables, and other preprocessor-related features

    are being worked into CSS as we speak. CSS Preprocessors are making CSS better.
  19. Be regular and orderly in your life so that you

    may be violent and original in your work.” ” —Gustave Flaubert