Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CSSカスタムプロパティと相対色構文で色管理
Search
umekobutea
October 27, 2023
Programming
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSSカスタムプロパティと相対色構文で色管理
umekobutea
October 27, 2023
Other Decks in Programming
See All in Programming
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
250
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
AmebaブログはKMPから卒業します
kmars0605
0
200
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
510
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Technical Leadership for Architectural Decision Making
baasie
3
600
The World Runs on Bad Software
bkeepers
PRO
72
12k
Test your architecture with Archunit
thirion
2
2.4k
Accessibility Awareness
sabderemane
1
250
Music & Morning Musume
bryan
48
7.4k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
Build your cross-platform service in a week with App Engine
jlugia
234
19k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
320
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Transcript
CSSカスタムプロパティと 相対色構文で色管理
Googleの作ったマテリアルデザインのカラーシステムをCSSのカスタムプロパティと相対色構文を使えばいい 感じに定義できるのでは?と思ったので試してみました。
自己紹介 名前 衣笠和樹 会社 株式会社シーズ 仕事 ECウェブサイトの実装など 使っている言語 PHP, JavaScript,
TypeScript
目次 1. マテリアルデザイン 1. カラーシステム 2. デザイントークン 2. CSSカスタムプロパティ 3.
相対色構文 1. Oklch 4. デモ 5. まとめ 6. ありがとうございました。 7. 参考
マテリアルデザイン Googleの作ったデザインシステム。 UIコンポーネントを用意してくれたり、色やタイポグラフィ、レイアウトのルールを決めてくれている。
カラーシステム キーカラー ベースとなる色 色調パレット 各キーカラーを明るさの階調 カラースキーム UIで使用する役割ごとに分けた色、色調パレットから色 を割り当てる
デザイントークン マテリアルデザインのスタイルの基盤。Web, スマホア プリなど複数のプラットフォームで共有できるように スタイルに必要な値に名前を付けて管理するもの。カ ラーシステムでは色調パレットとカラースキームの色 がデザイントークンとして定義されている。
CSSカスタムプロパティ 値を再利用するためのもの。デザイントークンはこれで定義する。 :root { /* reference */ --md-ref-color-primary-40: blue; --md-ref-color-primary-100:
white; /* system */ --md-sys-color-primary: var(--ref-color-primary-40); --md-sys-color-on-primary: var(--ref-color-primary-100); /* component */ --md-filled-button-container-color: var(--md-sys-color-primary); --md-filled-button-label-text-color: var(--md-sys-color-on-primary); } .filled-button { background-color: var(--md-filled-button-container-color); color: var(--md-filled-button-label-text-color); }
相対色構文 色の定義を絶対値ではなく、別の色を基に定義できるCSSの構文。これと後述するOklchを使えば色調パレ ットをキーカラーの指定だけでいい感じに定義できる。 まだほとんどのブラウザでサポートされてない。 Chromeは119でサポートされた。 :root { --md-ref-key-color-primary: blue; --md-ref-color-primary-10:
oklch(from var(--md-ref-key-color-primary) 10%, c h); --md-ref-color-primary-20: oklch(from var(--md-ref-key-color-primary) 20%, c h); --md-ref-color-primary-30: oklch(from var(--md-ref-key-color-primary) 30%, c h); }
Oklch 明度、彩度、色相で色を調整するときにはよくHSLを使われるが、Oklchはそれよりいいかんじの色空間。青 系の色相で明度を変えたときの違いが顕著で、Oklchの方が自然に感じる。HSLの方は明度を上げると紫っぽ くなる。 https://codepen.io/umekobutea/full/poqXWqa
デモ ソースコード https://github.com/umekobutea/color-theming-sample Google製のライブラリMaterial Webを使う https://material-web.dev/ マテリアルデザインのUIコンポーネントをWeb Componentで実装したもの。 デザイントークンをCSSカスタムプロパティで指定してスタイルをカスタマイズできる。
まとめ 簡単には使えなさそう デザイントークンの定義が大変。 ただ1度作ってしまえば再利用できそう。 OklchとHSLそれそれ一長一短。 Oklchは彩度の調整も必要そう。 https://bottosson.github.io/misc/colorpicker/ HSLは色にこだわりがなければ使えそう。 カラースキーマ(Surface Color)に適用されている色調のトーンがあってなさそう。
HSLにあわせてあるんじゃないかと思う。
ありがとうございました。
参考 https://m3.material.io/ https://triple-underscore.github.io/css-color5-ja.html https://developer.chrome.com/blog/css-relative-color-syntax/ https://bottosson.github.io/posts/oklab/ https://material-web.dev/