Skip to content

Instantly share code, notes, and snippets.

@harapeko
Created July 6, 2020 06:00
Show Gist options
  • Save harapeko/3f772d69fcb9deb924a782c4a3a8f810 to your computer and use it in GitHub Desktop.
Save harapeko/3f772d69fcb9deb924a782c4a3a8f810 to your computer and use it in GitHub Desktop.
突然CSSいじって言われたときSassなんだが、Sass...?とはにならないようにする為の20分

突然CSSいじって言われたときSassなんだが、Sass...?とはにならないようにする為の20分 〜 はじめてのSass 〜

本日内容

やらないこと

やること

  • 概要 1分
  • 競合 2分
  • 記法 1分
  • よく使う機能 15分くらい
    • Nesting
    • Variable, Interpolation
    • Parent Selector

概要

Sass is ツヨツヨなプリプロセッサ(前処理)でオラオラしてCSSに出力してくれるツール

CSS仕様上、CSSを動的にする訳にはいかない(マッチングと再レンダリングが恐ろしく増えるから) →せやツヨツヨ前処理 を CSSに変換したろ!

競合

記法

SASS記法と、後発のSCSS記法がある SCSS記法のほうが人気で、プラグイン対応も多い

よく使う機能

{ {} } Nesting

https://sass-lang.com/guide#topic-3

$ Variable

https://sass-lang.com/guide#topic-3

Interpolation(SassScript展開)

"#{$val}" 変数展開

$name: avatar;
.icon-#{$name} {
    background-image: url("/icons/#{$name}.svg");
    font-size: "#{(100 / 10)}";
}

.icon-avatar {
    background-image: url("/icons/avatar.svg");
    font-size: "10";
}

& Parent Selector (使わない方針の職場もある)

https://sass-lang.com/documentation/style-rules/parent-selector

参考URL

sass2css https://sass2css.herokuapp.com/

codepen https://codepen.io/

ユーティリティクラス作成例 https://gist.github.com/harapeko/449ce613d91b6c919111f169c92d9035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment