概要
color-me-sassはSass用のカラーライブラリです。
#7A991F
みたいな16進数カラーコードの代わりに$limeDark
など、色の名前で指定できるようになります。
body {
background: $limeDark;
}
いい感じのカラーがたくさん定義されていて便利そうなので、Rails4のプロジェクトで使ってみました。
bower-railsの準備
color-me-sass
を普通にbowerでインストールしてもいいのですが、試しにbower-railsを使ってみました。
Gemfileを編集してgroup :development, :test
のところにbower-rails
を追加します。
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Bower support for Rails projects.
gem 'bower-rails', "~> 0.10.0"
end
gemを追加、
$ bundle install
bower-rails
でインストールしたコンポーネントはvendor/assets/bower_components
配下に保存されるので、assetsのパスに登録しておきます。
config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
color-me-sassを追加
プロジェクト直下のBowerfile
に下の行を追加します。
# Colour library for the css preprocessor SASS
asset 'color-me-sass'
rakeコマンドを実行してインストール
$ rake bower:install
Sassで使ってみる
scssファイルを編集します。
@import "color-me-sass/_color-me-sass.scss";
body {
background: $limeDark;
}
Sassのlighten()
やdarken()
を組み合わせると明度を調節することもできます。
// lighten()で明るくする
body{
background: lighten($limeDark, 30%);
}
// darken()で暗くする
body{
background: darken($limeDark, 30%);
}