Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
CSSの未来を先取り!

CSS Preprocessorの
始めかた
                @adactio (CC BY2.0)
CSS
Preprocessor
CSS
Preprocessor
#main {
  float: right;
}
#main p {
  margin-bottom: 1em;
}
#main {
  float: right;
}
#main p {
  margin-bottom: 1em;
}
#main {                 #main {
  float: right;             float: right;
}                           p {
#main p {                       margin-bottom: 1em;
  margin-bottom: 1em;       }
}                       }
CSS
Preprocessor
CSS
Preprocessor
Css preprocessorの始めかた
Css preprocessorの始めかた
+
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
一緒に使うので
いちいち覚えなくてもOK
Sass・Compassの
    メリット
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
.box {
    @include border-radius(5px);
}
.box {
    @include border-radius(5px);
}


.box {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -ms-border-radius: 5px;
  -o-border-radius: 5px;
  border-radius: 5px;
}
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
#main {                 #main {
  float: right;             float: right;
}                           p {
#main p {                       margin-bottom: 1em;
  margin-bottom: 1em;       }
}                       }
省力?
      @epSos.de (CC BY 2.0)
まだまだ
   @epSos.de (CC BY 2.0)
Sass
#main {
    margin: 5px;
    a {
        text-decoration: none;
        &.link {
            display: inline-block;
        }
        &:hover {
            color: #F00;
        }
    }
}
CSS
#main {
  margin: 5px;
}
#main a {
  text-decoration: none;
}
#main a.link {
  display: inline-block;
}
#main a:hover {
  color: #F00;
}
Sass
#main {
    margin: 5px;
    a {
        text-decoration: none;
        &.link {
            display: inline-block;
        }
        &:hover {
            color: #F00;
        }
    }
}
Sass
#main {
    margin: 5px;
    a {
        text-decoration: none;
        &.link {
            display: inline-block;
        }
        &:hover {
            color: #F00;
        }
    }
}
CSS
#main {
  margin: 5px;
}
#main a {
  text-decoration: none;
}
#main a.link {
  display: inline-block;
}
#main a:hover {
  color: #F00;
}
ZERGE_VIOLATOR (CC BY 2.0)
ZERGE_VIOLATOR (CC BY 2.0)




           Media Queries
Css preprocessorの始めかた
#main {
                                         CSS
  float: left;
  width: 700px;
  margin: 0 auto;
}
@media screen and (max-width: 640px) {
  #main {
    float: none;
    width: 100%;
  }
}
Sass
#main {
    float: left;
    width: 700px;
    margin: 0 auto;
    @media screen and (max-width:640px) {
        float: none;
        width: 100%;
    }
}
#main {
                                         CSS
  float: left;
  width: 700px;
  margin: 0 auto;
}
@media screen and (max-width: 640px) {
  #main {
    float: none;
    width: 100%;
  }
}
#main {
                                         CSS
  float: left;
  width: 700px;
  margin: 0 auto;
}
@media screen and (max-width: 640px) {
  #main {
    float: none;
    width: 100%;
  }
}
Sass
#main {
    float: left;
    width: 700px;
    margin: 0 auto;
    @media screen and (max-width:640px) {
        float: none;
        width: 100%;
    }
}
Sass
#main {
    float: left;
    width: 700px;
    margin: 0 auto;
    @media screen and (max-width:640px) {
        float: none;
        width: 100%;
    }
}
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
photo by pakutaso.com
座標・幅    ブラウザ
 指定    キャッシュ




               photo by pakutaso.com
座標・幅    ブラウザ
 指定    キャッシュ




めんどくさい。

               photo by pakutaso.com
Css preprocessorの始めかた
Css preprocessorの始めかた
読み込み
読み込み

                      $share-sprite: sprite-map("share/*.png");
                      $share-sprite-url: sprite-url($share-sprite);




.logoArea {
    text-indent: 100%;
    overflow: hidden;
    white-space: normal;
    width: image-width(sprite-file($share-sprite,"logo"));
    height: image-height(sprite-file($share-sprite,"logo"));
    background-image: $share-sprite-url;
    background-repeat: no-repeat;
    background-position: sprite-position($share-sprite,"logo");
}
.logoArea {
    text-indent: 100%;
    overflow: hidden;
    white-space: normal;
    width: image-width(sprite-file($share-sprite,"logo"));
    height: image-height(sprite-file($share-sprite,"logo"));
    background-image: $share-sprite-url;
    background-repeat: no-repeat;
    background-position: sprite-position($share-sprite,"logo");
}
.logoArea {
    text-indent: 100%;
    overflow: hidden;
    white-space: normal;
    width: image-width(sprite-file($share-sprite,"logo"));
    height: image-height(sprite-file($share-sprite,"logo"));
    background-image: $share-sprite-url;
    background-repeat: no-repeat;
    background-position: sprite-position($share-sprite,"logo");
}



.logoArea {
     text-indent: 100%;
    overflow: hidden;
    white-space: normal;
    width: 419px;
    height: 62px;
    background-image: url('/img/share-s6664b1cfc3.png');
    background-repeat: no-repeat;
    background-position: 0 0;
}
.logoArea {
    text-indent: 100%;
    overflow: hidden;
    white-space: normal;
    width: image-width(sprite-file($share-sprite,"logo"));
    height: image-height(sprite-file($share-sprite,"logo"));
    background-image: $share-sprite-url;
    background-repeat: no-repeat;
    background-position: sprite-position($share-sprite,"logo");
}



.logoArea {
     text-indent: 100%;
    overflow: hidden;
    white-space: normal;
    width: 419px;
    height: 62px;
    background-image: url('/img/share-s6664b1cfc3.png');
    background-repeat: no-repeat;
    background-position: 0 0;
}
Variable
               CSS Sprite
Nesting



           +

 Mixin
               Vendor Prefix
  extend
@import url(reset.css);
             @import url(module.css);
             @import url(style.css);
import.css


#main {
  float: right;
}
#main p {
  margin-bottom: 1em;
}
@import url(reset.css);




                                    △
             @import url(module.css);
             @import url(style.css);
import.css


#main {
  float: right;
}
#main p {
  margin-bottom: 1em;
}
@import url(reset.css);




                                    △
             @import url(module.css);
             @import url(style.css);
import.css


#main {↓
  float: right;↓
....
}↓
#main p { ↓
  margin-bottom: 1em;↓
....
}
@import url(reset.css);




                                    △
             @import url(module.css);
             @import url(style.css);
import.css


#main {↓
  float: right;↓
....




                                    △
}↓
#main p { ↓
  margin-bottom: 1em;↓
....
}
@import "reset";
              @import "module";
              @import "style";
import.scss

              /*--- reset */
              html {
                  overflow-y: scroll;
              }
              body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,

import.css
              #header {
              }
#main {↓
  float: right;↓
....
}↓
#main p { ↓
  margin-bottom: 1em;↓
....
}
#main {↓
  float: right;↓
....
}↓
#main p { ↓
  margin-bottom: 1em;↓
....
}

$compass compile -s compressed style.scss
#main {↓
  float: right;↓
....
}↓
#main p { ↓
  margin-bottom: 1em;↓
....
}

$compass compile -s compressed style.scss
#main {↓
  float: right;↓
....
}↓
#main p { ↓
  margin-bottom: 1em;↓
....
}

$compass compile -s compressed style.scss



#main{float:right;}#main p{margin-bottom:1em;}
@flickrized (CC BY 2.0)




Try it!
× お試しなので、
コマンドプロンプトは使いません
Css preprocessorの始めかた
インストーラーをダウンロード




Scout - Compass and Sass without all the hassle
http://mhs.github.com/scout-app/
インストーラーをダウンロード
インストーラーに従って
   進むだけ
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
Input Folder
Sassファイルのディレクトリ
Input Folder
Sassファイルのディレクトリ



 Output Folder
CSSファイルのディレクトリ
site_data
            Input Folder
   _scss
     style.scss
            Output Folder
   css
     style.css
Css preprocessorの始めかた
Css preprocessorの始めかた
Images Folder
画像フォルダー(Sprite時)
Images Folder
画像フォルダー(Sprite時)




   Output Style
    書き出しスタイル

Nested 入れ子で
Expanded よく書く感じの
Compact 1行スタイル
Compressed 改行スペース削除
Nested
#main {
  width: 700px;
  float: left; }
  #main p {
    margin: 5px; }
Expanded
 #main {
   width: 700px;
   float: left;
 }
 #main p {
   margin: 5px;
 }
Compact
#main { width: 700px; float: left; }
#main p { margin: 5px; }
Compressed
#main{width:700px;float:left}#main p{margin:5px}
ファイル
可読性
                            サイズ
高                            大
      Nested     入れ子で
      Expanded   よく書く感じの
      Compact    1行スタイル
      Compressed 改行スペース削除
低                            低
ファイル
可読性
                            サイズ
高                            大
      Nested     入れ子で
      Expanded   よく書く感じの
      Compact    1行スタイル
      Compressed 改行スペース削除
低                            低
ファイル
可読性
                            サイズ
高                            大
      Nested     作業中
                 入れ子で
      Expanded   よく書く感じの
      Compact    1行スタイル
      Compressed 改行スペース削除
低                            低
                 リリース時
Images Folder
画像フォルダー(Sprite時)




   Output Style
    書き出しスタイル

Nested 入れ子で
Expanded よく書く感じの
Compact 1行スタイル
Compressed 改行スペース削除
Css preprocessorの始めかた
Css preprocessorの始めかた
style.scss
style.scss
style.scss   style.css
×
style.scss       style.css
site_data
   _scss
     style.scss
   css
site_data
   _scss
     style.scss
   css
site_data
   _scss 保存
     style.scss
   css
     style.css
Try!
                                      Try!
@Camera Eye Photography (CC BY 2.0)
                                      Try!
ま ず は 、     を 作って、
       のコ ピー
     イト
既存のサ
          実 験 !
  の 中 で
そ
Sassのあるある
 Sassのあるある



             @erix! (CC BY 2.0)
Css preprocessorの始めかた
Css preprocessorの始めかた
>>> Change detected at 16:05:43 to: style.scss
error style.scss (Line 6: Undefined mixin
'border-radius'.)
overwrite style.css
                          この前後が
                           あやしい
Css preprocessorの始めかた
CSS3のベンダープリフィックスには、
   Compassをインポートします
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
この前後が
                          あやしい

>>> Change detected at 16:41:11 to: style.scss
error style.scss (Line 4: Invalid CSS after " /
zoom": expected ///, was ":1;")
overwrite style.css
Css preprocessorの始めかた
プロパティの前に「/」があると
   エラーを返します
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
Css preprocessorの始めかた
まとめ
最初は
@mikebaird (CC BY 2.0)
                         難しい
慣れたら
最強
       @mikebaird (CC BY 2.0)
CSSの文法が正しければコンパイルOK

IE用ハックを書き換えるぐらい

既存のCSSをScoutに通してエラーを
一つ一つ潰す
Try!
                                      Try!
@Camera Eye Photography (CC BY 2.0)
                                      Try!
ま ず は 、     を 作って、
       のコ ピー
     イト
既存のサ
          実 験 !
  の 中 で
そ
@owenwbrown (CC BY 2.0)
参考ページ
【Sassを覚えよう!】もくじ的なのと参考リンク - CSS HappyLife
http://css-happylife.com/archives/2012/0130_0415.php
DreamweaverでSassファイルを編集するには? ¦ Webデザインのタネ
http://oshare.jugem.cc/?eid=795

More Related Content

Css preprocessorの始めかた