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を書くための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
6.1k
Other Decks in Programming
See All in Programming
XHTMLが残したもの
yosuke_furukawa
PRO
2
640
業務時間外もAIに働いてもらう話
colorful12
3
10k
Intent as Code
shoppingjaws
4
710
ソフトウェアラスタライザ
fadis
1
800
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
490
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
120
信頼性の目標を誰も求めてない
shubox
0
500
アクセシビリティから考える情報設計
high_g_engineer
0
350
高専キャリア LT 発表内容
crysta1221
6
5.6k
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
1.7k
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
2
270
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
How to Ace a Technical Interview
jacobian
281
24k
RailsConf 2023
tenderlove
30
1.5k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
420
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Rails Girls Zürich Keynote
gr2m
96
14k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
400
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
780
Heart Work Chapter 1 - Part 1
lfama
PRO
9
36k
What's in a price? How to price your products and services
michaelherold
247
13k
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で使えるようになれば導入?
ありがとうございました!