Movatterモバイル変換


[0]ホーム

URL:


2,867 views

Sass(SCSS)について

HTML5 勉強会@福岡 - 第16回 「LESS/Sass」について

Embed presentation

Downloaded 36 times
Sass(SCSS)についてHTML5 勉強会@福岡 - 第16回                      1
@kazu69 paperboy&co.                2
Today’s Agenda• Sassとは?• Sassの特徴• Sassを使った例• まとめ                         3
Sass(SCSS)とは?                4
Sass isSass - Syntactically awesome style sheetHampton Catlinが発案したRubyで書かれたCSS Preprocessorsの一つ。CSSファイルにするためにはコンパイル (.sassや.scss を .css に変換) が必要。HTMLのPreprocessorsにHamlから派生がしたものである。Sass記法とSCSS(Sassy sass)記法がある。                                           5
Sass is  CSSを速く、きれいにDRY(Don't Repeat Yourself) に    書くことができる                               6
Sass(SCSS)の特徴                7
mixinよく使うコードを再利用//mixin                  .color1 {@mixin color {             font-size: 1em;  color: #F00;             color: #F00; }}.color1 {                .color2 {  font-size: 1em;          font-size: .5em;  @include color;          color: #F00; }}.color2 {  font-size: .5em;  @include color;}                                              8
extendデザインを拡張する//@extend                      .box,.box {                         .box-red,  display: inline-block;       .box-fixHeight {  width: 20%;                    display: inline-block;  height: 100%;                  width: 20%;}                                height: 100%; }.box-red {                     .box-red {  @extend .box;                  background-color: #F00; }  background-color: #F00;}                              .box-fixHeight {                                 border: 2px solid #CCC; }.box-fixHeight {  @extend .box;  border: 2px solid #CCC;}        同じ作業をしないのでスピードアップ                                                             9
functions数値、文字列などで便利な関数が豊富//functionbody {  width: percentage(100px/200px);  opacity: rgba(#333, 0.2);  color: lighten(#333, 2);  &:before {    content: quote(hogemoge);  }}body {  width: 50%;  opacity: rgba(51, 51, 51, 0.2);  color: #383838; }  body:before {    content: "hogemoge"; }                                    10
custom functionなければ作ることもできる//custom function@function addSass($string) {  @return 'Sass' + $string;}.sass {  content: addSass('(Scss)');}.sass {  content: "Sass(Scss)"; }          案件に応じて柔軟な対応ができる                                   11
interpolation変数を柔軟に使うことができる//interpolation@mixin context($prop, $val) {  #{$prop}: $val;}.class {  @include context(color, black);  @include context(width,100px);}.class {  color: black;  width: 100px; }                                    12
iteratorfor / while / each がつかえる//@for                         .list-1 {@for $i from 1 through 3 {       color: #363636; }  .list-#{$i} {                .list-2 {    color: lighten(#333, $i)     color: #383838; }  }                            .list-3 {}                                color: #3b3b3b; }//@each                        .boo {@each $key in boo,foo,moo {      background-image:  .#{$key} {                   url("boo.png"); }    background-image:          .foo {url('#{$key}.png');              background-image:  }                            url("foo.png"); }}                              .moo {                                 background-image:                               url("moo.png"); }                                                     13
iteratorfor / while / each がつかえる//@while                      .col-3 {$i: 3;                          width: 0px; }@while $i > 0 {               .col-2 {  .col-#{$i} { width: 3px       width: 1px; }- $i; }                       .col-1 {  $i: $i - 1;                   width: 2px; }}                                                14
conditionalif~else がつかえる//@if                       /* $i==1 */$i: 1;                      .col-1 {@if $i == 0 {                 color: blue; }  .col-#{$i} {      color: red;  }}@else {  .col-#{$i} {      color: blue;  }}                                               15
CSS3 prefix面倒だったCSS3のprefixの処理も簡単にできる                                  .style {@mixin addPrefix($pref, $prop,                                    @include addPrefix($p, $r, .2em);$val:0) {                                    @include addPrefix($p, $a, button);  @if 1 < length($pref) {                                  }    @each $k in $pref {       #{$k}#{$prop}: $val;     }  }  @else {    #{$pref}#{$prop}: $val;       .style {  }                                 -webkit-border-radius: 0.2em;}                                   -moz-border-radius: 0.2em;                                    -ms-border-radius: 0.2em;$p: -webkit- -moz- -ms- -o- '';     -o-border-radius: 0.2em;$r: border-radius;                  border-radius: 0.2em;$a: appearance;                                    -webkit-appearance: button;                                    -moz-appearance: button;                                    -ms-appearance: button;                                    -o-appearance: button;                                    appearance: button; }                                                                          16
debug , errordebugなど標準出力もできる//@debug                        DEBUG: 2px@debug 1px + 1px;//@warn                         WARNING: 2pxになる@warn ‘2pxになる’;$x: 1px+1px;正しい構文でないとエラーとなりコンパイルできないbody {                          error test.scss (Line 3: Invalid    font-weight: bold           CSS after "    color": expected                                ";", was ": #333;")    color: #333;}単位付きの計算で正確な値を返してくれるp {                             p {  width: 1cm + 8mm;}              width: 1.8cm; }                                /* Lessだと9cmとなる */単位ごとに計算できないときはエラーになる                                                                   17
partialサイトのパフォーマンスを最適化 application.scss   _reset.scss   _global.scss   _layout.scss   _thema.scss             @import “reset”,”global”,”layout”,”thema” application.css     reset.css     global.css     layout.css     thema.css   複数のファイルを一つにまとめてコンパイル                    HTTPリクエストを減らせる                                                                              18
compile optionファイルの編集を監視できる                     ファイル単位    hoge.scss                            hoge.css         $sass --watch hoge.scss:hoge.css                    ディレクトリ単位      sass                                css                $sass --watch sass:css  ファイルが編集されると自動でコンパイル                                                    19
minify                   20KB                                                15KB     $sass --style compressed style.scss:style.cssbody{                                               body{background:#fff;font:62.5% palatino, "times  background: #fff;                                 new roman", serif;color:#333}strong{font-  font: 62.5% palatino, "times new roman", serif;   weight:bold}a:link,a:visited{color:#9C8A6A;text-  color: #333;                                      decoration:none}strong{  font-weight: bold;}a:link,a:visited{  color: #9C8A6A;}a:hover,a:active{  color: #3E372B;}       コードを圧縮(minify)してコンパイルできる                          ファイルサイズを減らせる                                                                                                       20
output styleその他の出力形式$sass --style nested style.scss:style.css#main {  color: #fff;  background-color: #000; }  #main p {    width: 10em; }$sass --style expanded style.scss:style.css#main {  color: #fff;  background-color: #000;}#main p {  width: 10em;}$sass --style compact style.scss:style.css#main { color: #fff; background-color: #000; }#main p { width: 10em; }                                                 21
convert    style.css                  style.scss   $ sass-convert style.css style.scss     CSSからSassやSCSSに変換できる運用中のサイトをSassに置き換えることもできるかも                                            22
convert                lessからSCSSに変換できる?           style.less                              style.scss           $ sass-convert syle.less style.scss* NOTE: Sass and Less are different languages, and they work differently.* I'll do my best to translate, but some features -- especially mixins --* should be checked by hand.undefined method `build' for module `Less::StyleSheet::Mixin4' (NameError)                                                                             23
Fire-SassFirefoxには便利なアドオン   $ sass —watch home.scss:test1.css —debug-info                                                   24
compass強力なCSSフレームワークがある      便利なmixinが準備されている      $gem install compass      $compass create <myproject>      $cd <myproject>      $compass watch                                    25
Sass3.2~メディアクエリが使えるようになるbreak-small: 320px;           profile-pic {$break-large: 1200px;           float: left;                                width: 250px;.profile-pic {                }  float: left;                @media screen and (max-  width: 250px;               width: 320px) {  @media screen and (max-       .profile-pic {width: $break-small) {            width: 100px;    width: 100px;                 float: none;    float: none;                }  }                           }  @media screen and (min-     @media screen and (min-width: $break-large) {        width: 1200px) {    float: right;               .profile-pic {  }                               float: right;}                               }                              }                                                        26
Sass3.2~placeholderも使える$break-small: 320px;@mixin respond-to($media) {  @media only screen and (max-width: $break-small){ @content; }}.profile-pic {  width: 250px;  @include respond-to(handhelds) { width: 100%;}}.profile-pic {  width: 250px;}@media only screen and (max-width: 320px) {  .profile-pic {    width: 100%;}}                                                     27
Sass(SCSS)の弱点                28
disadvantages  コンパイルにはRuby環境が必要      windowsはRuby installから‥  ターミナル操作(黒い画面)が必要GUIのアプリでターミナル操作は不要                                29
Sass(SCSS)を使った例                  30
choose reason SassSassを選んだ理由・CSSに近い感覚(記述)でつかえる・できるだけ簡単に使える・情報量が豊富で実績がある・強力なフレームワークがある・Lessよりも柔軟に使える・コンパイルしたCSSをリリースするので安心                             31
operation sample                                                               _import.scss                                   _import.scss                _color.scss  sass                  core                        mixins                                  配下のファイルを全て                   _font.scss                                                                    ・                                    importする                        ・                                                                    ・                                                               _page1.scss                                                               _page2.scss                                                   contents                                                                   ・             出力する    style.scss                                    ・                                                                   ・            ディレクトリ  css                                                          _const.scss                                                               _reset.scss                                    コンパイルされた        globals                                   ファイルをキャッシュ                  _layout.scss                     .sass-cache                                                                _nav.scssstyle.css               +                                       _footer.scss                                                  components    _btn.scss                                                                _form.scss                                                                   ・                                                                   ・                                                                   ・                                                                               32
まとめ      33
conclusion・SCSS記法だと記法習得コストは高くない・@mixinと@extendだけでも効率的になる・GUIツールを使えばターミナルが苦手でも十分使える・小規模な開発から導入してみるとわかりやすい・運用しつつノウハウをためて、mixinなどを充実させると より効率的になる・複数人で開発するときも役割分担しやすい・IE6,7,8のセレクター上限数(selector limit4096)には注意・Lessのように動的な変更ができない・CSSの癖が出にくく、クオリティも一定に保つことができる                                            34
Let’s Happy Sass Life                        35

Recommended

ZIP
実践Sass 後編
ZIP
実践Sass 前編
PDF
ネストを覚えた人のためのSassの便利な使い方
PDF
Webスライスから始めるmicroformats
PPT
Customization of DBIC::Schema::Loader
PDF
PDF
⑰jQueryをおぼえよう!その3
PDF
WebデザイナーのためのSass/Compass入門 先生:石本 光司
PDF
Frontend-Entwicklung mit SASS & Compass
PDF
Save time by using SASS/SCSS
PDF
Google App Engine and Social Apps
PPTX
Running with emmet and scss
PDF
Cloud Computing Bootcamp On The Google App Engine [v1.1]
PDF
Sassy Stylesheets with SCSS
PDF
Css to-scss
PDF
Scalable Apps with Google App Engine
PDF
GDD Brazil 2010 - What's new in Google App Engine and Google App Engine For B...
PPT
Developing Java Web Applications In Google App Engine
PDF
Turbo theming: Introduction to Sass & Compass
PDF
Theming and Sass
PDF
Front End Badassery with Sass
PDF
Stylesheet Wrangling with SCSS
 
PDF
Preprocessor presentation
PDF
Performance front end language
PDF
Getting Started with Sass & Compass
PPTX
老成的Sass&Compass
PPTX
Introduction to SASS
PPT
Learn Sass and Compass quick
PDF
First sass
PDF
Sass
 

More Related Content

ZIP
実践Sass 後編
ZIP
実践Sass 前編
PDF
ネストを覚えた人のためのSassの便利な使い方
PDF
Webスライスから始めるmicroformats
PPT
Customization of DBIC::Schema::Loader
PDF
PDF
⑰jQueryをおぼえよう!その3
PDF
WebデザイナーのためのSass/Compass入門 先生:石本 光司
実践Sass 後編
実践Sass 前編
ネストを覚えた人のためのSassの便利な使い方
Webスライスから始めるmicroformats
Customization of DBIC::Schema::Loader
⑰jQueryをおぼえよう!その3
WebデザイナーのためのSass/Compass入門 先生:石本 光司

Viewers also liked

PDF
Frontend-Entwicklung mit SASS & Compass
PDF
Save time by using SASS/SCSS
PDF
Google App Engine and Social Apps
PPTX
Running with emmet and scss
PDF
Cloud Computing Bootcamp On The Google App Engine [v1.1]
PDF
Sassy Stylesheets with SCSS
PDF
Css to-scss
PDF
Scalable Apps with Google App Engine
PDF
GDD Brazil 2010 - What's new in Google App Engine and Google App Engine For B...
PPT
Developing Java Web Applications In Google App Engine
PDF
Turbo theming: Introduction to Sass & Compass
PDF
Theming and Sass
PDF
Front End Badassery with Sass
PDF
Stylesheet Wrangling with SCSS
 
PDF
Preprocessor presentation
PDF
Performance front end language
PDF
Getting Started with Sass & Compass
PPTX
老成的Sass&Compass
PPTX
Introduction to SASS
PPT
Learn Sass and Compass quick
Frontend-Entwicklung mit SASS & Compass
Save time by using SASS/SCSS
Google App Engine and Social Apps
Running with emmet and scss
Cloud Computing Bootcamp On The Google App Engine [v1.1]
Sassy Stylesheets with SCSS
Css to-scss
Scalable Apps with Google App Engine
GDD Brazil 2010 - What's new in Google App Engine and Google App Engine For B...
Developing Java Web Applications In Google App Engine
Turbo theming: Introduction to Sass & Compass
Theming and Sass
Front End Badassery with Sass
Stylesheet Wrangling with SCSS
 
Preprocessor presentation
Performance front end language
Getting Started with Sass & Compass
老成的Sass&Compass
Introduction to SASS
Learn Sass and Compass quick

Similar to Sass(SCSS)について

PDF
First sass
PDF
Sass
 
PDF
HTML/CSSを効率的にする メタ言語とツールのアレコレ
PDF
CSS3 Design Recipe
PDF
Css拡張言語のコトハジメ
PDF
Sass/Compass講習会
PDF
コーディングがラクになる!? “自分仕様”のさくさくコーディング法
PDF
マークアップ講座 02 CSS
PDF
Sass introduction (jscafe 10)
PDF
gulp + sass で目指せ倍速コーディング(東区フロントエンド勉強会 2015年 第1回) 本編
PDF
About Sass
PDF
Css
PDF
リファクタリングHTML/CSS ~レガシー世界を超えて~ #scripty03
PDF
メディア芸術基礎 Ⅰ 第4回:CSS入門 情報の形を視覚化する
PDF
大阪Node学園八時限目 「コーディングのためのless - 基礎編 -」
PDF
PDF
CSS3の最新事情
PDF
jQuery Performance Tips – jQueryにおける高速化 -
PDF
なんでCSSすぐ死んでしまうん
PDF
CSS Design and Programming
First sass
Sass
 
HTML/CSSを効率的にする メタ言語とツールのアレコレ
CSS3 Design Recipe
Css拡張言語のコトハジメ
Sass/Compass講習会
コーディングがラクになる!? “自分仕様”のさくさくコーディング法
マークアップ講座 02 CSS
Sass introduction (jscafe 10)
gulp + sass で目指せ倍速コーディング(東区フロントエンド勉強会 2015年 第1回) 本編
About Sass
Css
リファクタリングHTML/CSS ~レガシー世界を超えて~ #scripty03
メディア芸術基礎 Ⅰ 第4回:CSS入門 情報の形を視覚化する
大阪Node学園八時限目 「コーディングのためのless - 基礎編 -」
CSS3の最新事情
jQuery Performance Tips – jQueryにおける高速化 -
なんでCSSすぐ死んでしまうん
CSS Design and Programming

Sass(SCSS)について


[8]ページ先頭

©2009-2025 Movatter.jp