Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
きれいなCSSを書くためのTools
Search
kou
June 16, 2018
Programming
460
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
きれいなCSSを書くためのTools
きれいなCSSを書くためのツールの紹介です。
kou
June 16, 2018
More Decks by kou
See All by kou
Angular Webアプリケーションの最新設計手法.pdf
koumatsumot0
7
12k
NgRx v7
koumatsumot0
1
530
NgRxについて考えたこと
koumatsumot0
0
260
AngularアプリケーションにおけるCSS設計手法
koumatsumot0
8
6k
Other Decks in Programming
See All in Programming
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
180
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
スマートグラスで並列バイブコーディング
hyshu
0
280
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
460
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
120
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
430
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
4.7k
関数型プログラミングのメリットって何だろう?
wanko_it
0
150
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.9k
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Odyssey Design
rkendrick25
PRO
2
730
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Everyday Curiosity
cassininazir
0
250
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Skip the Path - Find Your Career Trail
mkilby
1
160
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
YesSQL, Process and Tooling at Scale
rocio
174
15k
Transcript
きれいなCSSを書くためのTools Meguro.css #1
@kou 株式会社bitbank
今日話すこと 1. きれいなCSSとはなにか 2. きれいなCSSを書くためのTools紹介
きれいなCSSとは
きれいなCSSとは 1. コードの見た目が統一されている a. インデントや空行 b. コメントの形式 2. コードの書き方が統一されている a.
命名規則 b. レイアウト手法 c. 数値や単位
.wrapper{ ul{ margin: 0; padding: 0; li{ margin-left: 10px; list-style-type:
decimal; font-family: "Helvetica Neue"; width: 400px; padding: 14px 0; text-align: center; display: block; border-radius: 5px; ol { color: #9a9A9a; padding-left: 0.5em; li { list-style-type: circle; } } } } .user-list { margin: 0; padding: 0; .user-list-item { border-radius: 5px; display: block; font-family: 'Helvetica Neue'; list-style-type: decimal; margin-left: 10px; padding: 14px 0; text-align: center; width: 400px; } } .friend-list { color: #9a9a9a; padding-left: 5px; .friend-list-item { list-style-type: circle; } }
できるだけコードはきれいに書こう! 1. 見通しの悪いコードはバグのもとになる 2. 複雑なセレクタ条件などで書かれたコードは変更し辛い 3. 書く時間よりも読む時間の方が圧倒的に長い
現実は 1. コードを書くのがエンジニアだけじゃない 2. エンジニアの中でもコーディングのスキル差がある 3. 手っ取り早くコピペで終わらす場合も多々ある 4. 無駄な上書きや間違ったコードがあってもなんとなく動いてしまう
自動的な整形、Lintツールが必要!
None
CSScomb
CSScombがすること 1. インデントの自動整形 a. スペース/タブの統一 b. コロンの後のスペース、セミコロン後の改行の有無など 2. プロパティの並び替え a.
アルファベット順、自分の指定した順番など 3. ダブルクォーテーション/シングルクォーテーションの変換 a. “Meiryo UI” to ‘Meiryo UI’ 4. などなど
{ "always-semicolon": true, "block-indent": " ", "color-case": "lower", "color-shorthand": false,
"element-case": "lower", "eof-newline": true, "leading-zero": true, "quotes": "single", "remove-empty-rulesets": true, "space-after-colon": " ", "space-after-combinator": " ", "space-after-opening-brace": "\n", "space-after-selector-delimiter": "\n", "space-before-closing-brace": "\n", "space-before-colon": "", "space-before-combinator": " ", "space-before-opening-brace": " ", "space-before-selector-delimiter": "", "strip-spaces": true, "unitless-zero": true, "vendor-prefix-align": false, "sort-order": [...] } const Comb = require('csscomb'); gulp.task('csscomb', () => { const config = require('.csscomb.json'); const comb = new Comb(config); return comb.processDirectory('src'); });
.wrapper{ ul{ margin: 0; padding: 0; li{ margin-left: 10px; list-style-type:
decimal; font-family: "Helvetica Neue"; width: 400px; padding: 14px 0; text-align: center; display: block; border-radius: 5px; ol { color: #9a9A9a; padding-left: 0.5em; li { list-style-type: circle; } } } } .wrapper { ul { margin: 0; padding: 0; li { border-radius: 5px; display: block; font-family: 'Helvetica Neue'; list-style-type: decimal; margin-left: 10px; padding: 14px 0; text-align: center; width: 400px; ol { color: #9a9a9a; padding-left: 0.5em; li { list-style-type: circle; } } } } }
Stylelint
Stylelintがすること 1. インデント、コードスタイルの統一 a. CSScombはあくまでプロパティの順番変更がメインの仕事 b. CSScombだと空行の数などまでチェックできない c. CSScombよりも細かいコードスタイルをチェックできる 2.
単位や色指定の方法を統一 a. pxなどの単位で指定できるものを制限 3. 自分のルールをプラグインとして作れる a. かなり自由に作れる b. セレクタの多重ネストを禁止する、名前の規則など
{ "block-no-empty": true, "color-hex-case": "lower", "color-no-invalid-hex": true, "declaration-colon-space-after":"always", "indentation": 2,
"length-zero-no-unit": true, "max-line-length": 140, "max-empty-lines": 1, "max-nesting-depth": 1, "no-eol-whitespace": true, "no-missing-end-of-source-newline": true, "number-leading-zero": "always", "number-no-trailing-zeros": true, "rule-empty-line-before": [ "always", { "except": ["first-nested"], "ignore": ["after-comment"] } ], ... } stylelint 'src/**/*.scss' \ --config stylelint-config.json \ --syntax scss stylelint 'src/**/*.scss' \ --config stylelint-config.json \ --syntax scss \ --fix
.wrapper { ul { margin: 0; padding: 0; li {
border-radius: 5px; display: block; font-family: 'Helvetica Neue'; list-style-type: decimal; margin-left: 10px; padding: 14px 0; text-align: center; width: 400px; ol { color: #9a9a9a; padding-left: 0.5em; li { list-style-type: circle; } } } } } .user-list { margin: 0; padding: 0; .user-list-item { border-radius: 5px; display: block; font-family: 'Helvetica Neue'; list-style-type: decimal; margin-left: 10px; padding: 14px 0; text-align: center; width: 400px; } } .friend-list { color: #9a9a9a; padding-left: 5px; .friend-list-item { list-style-type: circle; } }
CSSComb & Stylelintを使うことで • 雑に書いても、コードを自動的に修正してくれるので楽になる • 誰が書いてもある程度規則的な、見通しのいいコードになる
さらに出来れば • CIに統合して、レビュー負荷を下げる • prettireがscssで使えるようになれば導入?
ありがとうございました!