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

Sassをはじめよう!

 Sassをはじめよう!

DIST.1 「Sass」 発表資料

448jp | OKI Yoshiya

February 17, 2014
Tweet

More Decks by 448jp | OKI Yoshiya

Other Decks in Technology

Transcript

  1. Sass is the most mature, stable, and powerful professional grade

    CSS extension language in the world. http://sass-lang.com/
  2. とりあえずどんなもんか #content { background-color: #ff0000; } #content h1 { margin-bottom:

    1em; } #content p { line-height: 2em; } #content { background-color: #ff0000; h1 { margin-bottom: 1em; } p { line-height: 2em; } }
  3. SASS記法とSCSS記法 #content background-color: #ff0000 h1 margin-bottom: 1em p line-height: 2em

    #content { background-color: #ff0000; h1 { margin-bottom: 1em; } p { line-height: 2em; } } SASS記法 SCSS記法
  4. ルールのネスト #content { background-color: #ff0000; h1 { margin-bottom: 1em; }

    p { line-height: 2em; } } #content { background-color: red; } #content h1 { margin-bottom: 1em; } #content p { line-height: 2em; } Sass CSS
  5. 親セレクタの参照 #content a { background-color: #ff0000; &:hover { background-color: #ffff00;

    } } #content a { background-color: #ff0000; } #content a:hover { background-color: #ffff00; } Sass CSS
  6. プロパティのネスト #content .book { border: { left: 5px solid #ff0000;

    bottom: { width: 5px; style: solid; color: #ff0000; } } } #content .book { border-left: 5px solid #FF0000; border-bottom-width: 5px; border-bottom-style: solid; border-bottom-color: #FF0000; } Sass CSS
  7. 通常のコメント /* イケてるスタイル */ #content { background-color: #ff0000; } /*

    イケてるスタイル */ #content { background-color: #ff0000; } Sass CSS
  8. 変数 $niceColor: #ff0000; #content { background-color: $niceColor; h1 { border-bottom:

    1px solid $niceColor; } } #content { background-color: red; } #content h1 { border-bottom: 1px solid red; } Sass CSS
  9. 変数のスコープ #content { $niceColor: #ff0000; background-color: $niceColor; } h1 {

    border-bottom: 1px solid $niceColor; } error screen.scss (Line 6: Undefined variable: "$niceColor".) Sass CSS
  10. 四則演算 #content { background-color: #ff0000; width: 980px – 40px; }

    #content { background-color: #ff0000; width: 940px; } Sass CSS
  11. 独自の関数 @function getDouble($value) { @return $value * 2; } #content

    { background-color: #ff0000; width: getDouble(200px); } #content { background-color: #ff0000; width: 400px; } Sass CSS
  12. スタイルの継承 .content { background-color: #ff0000; border: 1px solid #000000; }

    .sub { @extend .content; } .content, .sub { background-color: #ff0000; border: 1px solid #000000; } Sass CSS
  13. ミックスイン @mixin clearfix { &:after { content: ""; clear: both;

    display: block; } } .content { @include clearfix; background-color: #ff0000; } .content { background-color: #ff0000; } .content:after { content: ""; clear: both; display: block; } Sass CSS
  14. ミックスイン(引数) @mixin myBorder($width) { border: $width solid #00ff00; } .content

    { @include myBorder(5px); background-color: #ff0000; } .content { border: 5px solid lime; background-color: #ff0000; } Sass CSS
  15. Thank you ! Photo Credit:  mak1e  Nathan O'Nions

     *christopher*  Brett Jordan