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
450
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
520
NgRxについて考えたこと
koumatsumot0
0
260
AngularアプリケーションにおけるCSS設計手法
koumatsumot0
8
6k
Other Decks in Programming
See All in Programming
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
510
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
130
New "Type" system on PicoRuby
pocke
1
830
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
240
OSもどきOS
arkw
0
540
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.2k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
720
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.4k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
220
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
240
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
Claspは野良GASの夢をみるか
takter00
0
180
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
470
Measuring & Analyzing Core Web Vitals
bluesmoon
9
860
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
570
Statistics for Hackers
jakevdp
799
230k
For a Future-Friendly Web
brad_frost
183
10k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.7k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
180
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
240
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
210
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で使えるようになれば導入?
ありがとうございました!