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
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
130
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
250
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
220
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
830
Webフレームワークの ベンチマークについて
yusukebe
0
200
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
570
1B+ /day規模のログを管理する技術
broadleaf
0
130
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.7k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.7k
継続モナドとリアクティブプログラミング
yukikurage
3
410
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Deep Space Network (abreviated)
tonyrice
0
220
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Mobile First: as difficult as doing things right
swwweet
225
10k
Discover your Explorer Soul
emna__ayadi
2
1.2k
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で使えるようになれば導入?
ありがとうございました!