css preprocessorの始めかた

124
CSSの未来を先取り! CSS Preprocessor始めかた @ adactio (CC BY2.0)

Upload: hiroki-shibata

Post on 16-Jun-2015

5.958 views

Category:

Technology


0 download

DESCRIPTION

前知識がない人のためのSassの始めかたです。

TRANSCRIPT

Page 1: Css preprocessorの始めかた

CSSの未来を先取り!

CSS Preprocessorの始めかた

@adactio (CC BY2.0)

Page 2: Css preprocessorの始めかた

CSSPreprocessor

Page 3: Css preprocessorの始めかた

CSSPreprocessor

Page 4: Css preprocessorの始めかた

#main {  float: right;}#main p {  margin-bottom: 1em;}

Page 5: Css preprocessorの始めかた

#main {  float: right;}#main p {  margin-bottom: 1em;}

Page 6: Css preprocessorの始めかた

#main {    float: right;    p {        margin-bottom: 1em;    }}

#main {  float: right;}#main p {  margin-bottom: 1em;}

Page 7: Css preprocessorの始めかた

CSSPreprocessor

Page 8: Css preprocessorの始めかた

CSSPreprocessor

Page 9: Css preprocessorの始めかた
Page 10: Css preprocessorの始めかた
Page 11: Css preprocessorの始めかた

+

Page 12: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 13: Css preprocessorの始めかた

一緒に使うのでいちいち覚えなくてもOK

Page 14: Css preprocessorの始めかた

Sass・Compassのメリット

Page 15: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 16: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 17: Css preprocessorの始めかた

.box {    @include border-radius(5px);}

Page 18: Css preprocessorの始めかた

.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;}

Page 19: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 20: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 21: Css preprocessorの始めかた

#main {    float: right;    p {        margin-bottom: 1em;    }}

#main {  float: right;}#main p {  margin-bottom: 1em;}

Page 24: Css preprocessorの始めかた

#main {    margin: 5px;    a {        text-decoration: none;        &.link {            display: inline-block;        }        &:hover {            color: #F00;        }    }}

Sass

Page 25: Css preprocessorの始めかた

#main {  margin: 5px;}#main a {  text-decoration: none;}#main a.link {  display: inline-block;}#main a:hover {  color: #F00;}

CSS

Page 26: Css preprocessorの始めかた

#main {    margin: 5px;    a {        text-decoration: none;        &.link {            display: inline-block;        }        &:hover {            color: #F00;        }    }}

Sass

Page 27: Css preprocessorの始めかた

#main {    margin: 5px;    a {        text-decoration: none;        &.link {            display: inline-block;        }        &:hover {            color: #F00;        }    }}

Sass

Page 28: Css preprocessorの始めかた

#main {  margin: 5px;}#main a {  text-decoration: none;}#main a.link {  display: inline-block;}#main a:hover {  color: #F00;}

CSS

Page 30: Css preprocessorの始めかた

Media Queries

ZERGE_VIOLATOR (CC BY 2.0)

Page 31: Css preprocessorの始めかた
Page 32: Css preprocessorの始めかた

#main {  float: left;  width: 700px;  margin: 0 auto;}@media screen and (max-width: 640px) {  #main {    float: none;    width: 100%;  }}

CSS

Page 33: Css preprocessorの始めかた

#main {    float: left;    width: 700px;    margin: 0 auto;    @media screen and (max-width:640px) {        float: none;        width: 100%;    }}

Sass

Page 34: Css preprocessorの始めかた

#main {  float: left;  width: 700px;  margin: 0 auto;}@media screen and (max-width: 640px) {  #main {    float: none;    width: 100%;  }}

CSS

Page 35: Css preprocessorの始めかた

#main {  float: left;  width: 700px;  margin: 0 auto;}@media screen and (max-width: 640px) {  #main {    float: none;    width: 100%;  }}

CSS

Page 36: Css preprocessorの始めかた

#main {    float: left;    width: 700px;    margin: 0 auto;    @media screen and (max-width:640px) {        float: none;        width: 100%;    }}

Sass

Page 37: Css preprocessorの始めかた

#main {    float: left;    width: 700px;    margin: 0 auto;    @media screen and (max-width:640px) {        float: none;        width: 100%;    }}

Sass

Page 38: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 39: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 41: Css preprocessorの始めかた

座標・幅指定

ブラウザキャッシュ

photo by pakutaso.com

Page 42: Css preprocessorの始めかた

座標・幅指定

めんどくさい。

ブラウザキャッシュ

photo by pakutaso.com

Page 43: Css preprocessorの始めかた
Page 44: Css preprocessorの始めかた
Page 45: Css preprocessorの始めかた

読み込み

Page 46: Css preprocessorの始めかた

読み込み

.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");}

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

Page 47: Css preprocessorの始めかた

.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");}

Page 48: Css preprocessorの始めかた

.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;}

Page 49: Css preprocessorの始めかた

.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;}

Page 50: Css preprocessorの始めかた

CSS Sprite

Vendor Prefix

Variable

Mixin

Nesting

extend

+

Page 51: Css preprocessorの始めかた

import.css

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

#main {  float: right;}#main p {  margin-bottom: 1em;}

Page 52: Css preprocessorの始めかた

import.css

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

#main {  float: right;}#main p {  margin-bottom: 1em;}

Page 53: Css preprocessorの始めかた

import.css

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

#main {  float: right;}#main p {  margin-bottom: 1em;}

↓↓

↓↓

....

....

Page 54: Css preprocessorの始めかた

import.css

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

#main {  float: right;}#main p {  margin-bottom: 1em;}

↓↓

↓↓

....

.... △

Page 55: Css preprocessorの始めかた

import.scss

@import "reset";@import "module";@import "style";

import.css

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

#header {}

Page 56: Css preprocessorの始めかた

#main {  float: right;}#main p {  margin-bottom: 1em;}

↓↓

↓↓

....

....

Page 57: Css preprocessorの始めかた

#main {  float: right;}#main p {  margin-bottom: 1em;}

↓↓

↓↓

....

....

$compass compile -s compressed style.scss

Page 58: Css preprocessorの始めかた

#main {  float: right;}#main p {  margin-bottom: 1em;}

↓↓

↓↓

....

....

$compass compile -s compressed style.scss

Page 59: Css preprocessorの始めかた

#main {  float: right;}#main p {  margin-bottom: 1em;}

↓↓

↓↓

....

....

#main{float:right;}#main p{margin-bottom:1em;}

$compass compile -s compressed style.scss

Page 61: Css preprocessorの始めかた

お試しなので、コマンドプロンプトは使いません

×

Page 62: Css preprocessorの始めかた
Page 63: Css preprocessorの始めかた

インストーラーをダウンロード

Scout - Compass and Sass without all the hasslehttp://mhs.github.com/scout-app/

Page 64: Css preprocessorの始めかた

インストーラーをダウンロード

Page 65: Css preprocessorの始めかた

インストーラーに従って進むだけ

Page 66: Css preprocessorの始めかた
Page 67: Css preprocessorの始めかた
Page 68: Css preprocessorの始めかた
Page 69: Css preprocessorの始めかた
Page 70: Css preprocessorの始めかた
Page 71: Css preprocessorの始めかた

Input FolderSassファイルのディレクトリ

Page 72: Css preprocessorの始めかた

Input FolderSassファイルのディレクトリ

Output FolderCSSファイルのディレクトリ

Page 73: Css preprocessorの始めかた

site_data

css

_scssstyle.scss

style.css

Input Folder

Output Folder

Page 74: Css preprocessorの始めかた
Page 75: Css preprocessorの始めかた
Page 76: Css preprocessorの始めかた

Images Folder画像フォルダー(Sprite時)

Page 77: Css preprocessorの始めかた

Images Folder画像フォルダー(Sprite時)

Output Style書き出しスタイル

Nested 入れ子でExpanded よく書く感じのCompact 1行スタイルCompressed 改行スペース削除

Page 78: Css preprocessorの始めかた

Nested#main {  width: 700px;  float: left; }  #main p {    margin: 5px; }

Page 79: Css preprocessorの始めかた

Expanded#main {  width: 700px;  float: left;}#main p {  margin: 5px;}

Page 80: Css preprocessorの始めかた

Compact

#main { width: 700px; float: left; }#main p { margin: 5px; }

Page 81: Css preprocessorの始めかた

Compressed

#main{width:700px;float:left}#main p{margin:5px}

Page 82: Css preprocessorの始めかた

Nested 入れ子でExpanded よく書く感じのCompact 1行スタイルCompressed 改行スペース削除

可読性 ファイルサイズ

Page 83: Css preprocessorの始めかた

Nested 入れ子でExpanded よく書く感じのCompact 1行スタイルCompressed 改行スペース削除

可読性 ファイルサイズ

Page 84: Css preprocessorの始めかた

Nested 入れ子でExpanded よく書く感じのCompact 1行スタイルCompressed 改行スペース削除

可読性 ファイルサイズ

作業中

リリース時

Page 85: Css preprocessorの始めかた

Images Folder画像フォルダー(Sprite時)

Output Style書き出しスタイル

Nested 入れ子でExpanded よく書く感じのCompact 1行スタイルCompressed 改行スペース削除

Page 86: Css preprocessorの始めかた
Page 87: Css preprocessorの始めかた
Page 88: Css preprocessorの始めかた

style.scss

Page 89: Css preprocessorの始めかた

style.scss

Page 90: Css preprocessorの始めかた

style.scss style.css

Page 91: Css preprocessorの始めかた

style.scss style.css

×

Page 92: Css preprocessorの始めかた

site_data

css

_scssstyle.scss

Page 93: Css preprocessorの始めかた

site_data

css

_scssstyle.scss

Page 94: Css preprocessorの始めかた

style.css

site_data

css

_scssstyle.scss

保存

Page 96: Css preprocessorの始めかた

既存のサイトのコピー

を作って、

その中で実験!

まずは、

Page 97: Css preprocessorの始めかた

SassのあるあるSassのあるある

@erix! (CC BY 2.0)

Page 98: Css preprocessorの始めかた
Page 99: Css preprocessorの始めかた
Page 100: Css preprocessorの始めかた

>>> Change detected at 16:05:43 to: style.scsserror style.scss (Line 6: Undefined mixin 'border-radius'.)overwrite style.css

この前後があやしい

Page 101: Css preprocessorの始めかた
Page 102: Css preprocessorの始めかた

CSS3のベンダープリフィックスには、Compassをインポートします

Page 103: Css preprocessorの始めかた
Page 104: Css preprocessorの始めかた
Page 105: Css preprocessorの始めかた
Page 106: Css preprocessorの始めかた
Page 107: Css preprocessorの始めかた
Page 108: Css preprocessorの始めかた

>>> Change detected at 16:41:11 to: style.scsserror style.scss (Line 4: Invalid CSS after " /zoom": expected /\//, was ":1;")overwrite style.css

この前後があやしい

Page 109: Css preprocessorの始めかた
Page 110: Css preprocessorの始めかた

プロパティの前に「/」があるとエラーを返します

Page 111: Css preprocessorの始めかた
Page 112: Css preprocessorの始めかた
Page 113: Css preprocessorの始めかた
Page 114: Css preprocessorの始めかた
Page 115: Css preprocessorの始めかた

まとめ

Page 116: Css preprocessorの始めかた

最初は難しい

@mikebaird (CC BY 2.0)

Page 117: Css preprocessorの始めかた

慣れたら最強

@mikebaird (CC BY 2.0)

Page 118: Css preprocessorの始めかた

CSSの文法が正しければコンパイルOK

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

既存のCSSをScoutに通してエラーを一つ一つ潰す

Page 120: Css preprocessorの始めかた

既存のサイトのコピー

を作って、

その中で実験!

まずは、

Page 122: Css preprocessorの始めかた

参考ページ

Page 123: Css preprocessorの始めかた

【Sassを覚えよう!】もくじ的なのと参考リンク - CSS HappyLifehttp://css-happylife.com/archives/2012/0130_0415.php

Page 124: Css preprocessorの始めかた

DreamweaverでSassファイルを編集するには? | Webデザインのタネhttp://oshare.jugem.cc/?eid=795