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
Kuro Hsu
June 05, 2019
Education
2.8k
10
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSS 不是我們想像的這麼簡單! [台北場]
v-tw meetup #1 2019/06/05
活動錄影:
https://www.youtube.com/watch?v=dtX51ru_eXU
Kuro Hsu
June 05, 2019
More Decks by Kuro Hsu
See All by Kuro Hsu
Laravel x Vite
kurotanshi
0
720
[.NET Conf 2020 Taiwan] 以輕前端視角進入 Vue 3.0 的世界
kurotanshi
0
820
[MOPCON 2020] vite: Make web dev fast again
kurotanshi
0
2.5k
[ModernWeb'20] Vue.js :The Bad Parts
kurotanshi
1
220
[MOPCON 2019] Vue.js 3.0 與 Composition API 的變革
kurotanshi
1
1.4k
[JSDC2019] 我有一堆選擇 Vue 開發框架的理由
kurotanshi
1
890
[COSCUP 2019] 前端工程師的養成之路與開源工具
kurotanshi
3
480
初探 Vue 3.0 Function API
kurotanshi
4
3.1k
VueJS Style Guide 導讀
kurotanshi
6
1.9k
Other Decks in Education
See All in Education
【新規入学者様】ZEPメタバース校舎ガイド
ainischool
0
190
INTRODUCTION TO THE CELL
pawan_pharm
0
320
Comentario del plano urbano de Madrid hasta 1860 (1ª parte )
juanmartin2026
1
100k
FA26 CLU MS Clinical Psychology New Student Orientation
jdbedics
0
180
データマネジメント試験対策教材1〜データマネジメント基礎〜
yoshimura_datam
1
810
学生のうちに考えておきたい信頼の話
suisan
1
830
Geografía y Fútbol: Chattanooga Geografía del Búnker de La Roja.
juanmartin2026
1
12k
Introduction to M&A
bvr7352
0
230
LEGO Geometry Tutorial
arnoknobbe
0
690
Tema 1. El relieve de España: Formación y características
juanmartin2026
0
38k
20260908_ターゲットとスコープを決める発表法
masakiokuda
1
130
新入社員を「あの子」と呼ばない運動 -PBL その前に- / Stop Calling New Hires "Kids"
aokiplayer
2
910
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
WENDY [Excerpt]
tessaabrams
14
40k
Skip the Path - Find Your Career Trail
mkilby
1
250
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
740
The Curious Case for Waylosing
cassininazir
1
560
Speed Design
sergeychernyshev
33
2.1k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
280
Mobile First: as difficult as doing things right
swwweet
225
10k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Embracing the Ebb and Flow
colly
88
5.2k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Transcript
CSS 不是我們想像的 這麼簡單! Kuro Hsu @ v-tw meetup #1 2019/06/05
̨̏ఙ
感謝場地⽀支援
Kuro Hsu https://kuro.tw
[email protected]
@kurotanshi
我今天不是來來教⼤大家寫 CSS 的
⾝身為前端⼯工程師 你認為 CSS 是什什麼?
代碼寫進去 畫⾯面跑出來來 前端發⼤大財 ⼤大家以為的 CSS
實際上的 CSS
CSS 好難 CSS
https://www.slideshare.net/kurotanshi/css-oocss-smacss-bem
https://www.slideshare.net/kurotanshi/css-oocss-smacss-bem
CSS 出了了什什麼問題
None
None
Simple !== Easy
⿊黑暗時期 樣式、腳本、結構⼤大鍋炒 <font size="3" color="red">…</font> <center onclick="…">…</center> <b>…</b> <i>…</i> <u>…</u>
https://twitter.com/ivantodorov/status/324420248201736195
None
CAPFPP Copy And Paste From Past Projects
古典時期 網⾴頁結構的關注點分離
http://www.csszengarden.com/tr/zh-tw/
http://www.csszengarden.com/219/
http://www.csszengarden.com/215/
http://www.csszengarden.com/220/
• ⼿手⼯工藝之美 • HTML、CSS、JS 依照功能拆分 • 結構良好、具語意的 HTML • 不同的
CSS 賦予不同⾯面貌
None
None
None
None
None
!important
None
困境 • Class 命名 • CSS Code 難以重複使⽤用 • 樣式的優先序與衝突
• !important
啟蒙時代 CSS ⽅方法論的崛起
OOCSS 那年年代物件導向正夯
兩兩⼤大原則 • Separate Structure and Skin 結構與外觀分離 • Separate Container
and Content 容器與內容分離
<div class="media"> <div class="media-img"> <img src="http://placehold.it/80x80" alt=""> </div> <div class="media-body">
<p>...</p> </div> </div>
<div class="media media-shadow"> <div class="media-img"> <img src="http://placehold.it/80x80" alt=""> </div> <div
class="media-body"> <p>...</p> </div> </div>
<div class="media media-no-border"> <div class="media-img"> <img src="http://placehold.it/80x80" alt=""> </div> <div
class="media-body"> <p>...</p> </div> </div>
None
None
None
模組化、架構化
良好的 CSS 架構 • 可預測性 - Predictable • 可重複使⽤用 -
Reusable • 容易易維護 - Maintainable • 可擴充性 - Scalable
第⼀一次⼯工業⾰革命 Sass / Compass / Stylus…
None
SMACSS Scalable and Modular Architecture for CSS
將結構分類 • Base - CSS Reset / CSS Normalize /
global styles… • Layout - header / footer / content / sidebar … • Module - list / button / components … • State - active / error / hidden … • Theme
Layout
Module
State
CSS 與 HTML 分離
.box, .box h2, .box ul, .box p { … }
.box, .box h2, .box ul, .box p { … }
.box, .box .header, .box .body { … }
.box, .box h2, .box ul, .box p { … }
.box, .box .header, .box .body { … } .box, .box-header, .box-body { … }
命名學 BEM
元件時代的濫濫觴 • B - Block • E - Element •
M - Modifier
None
None
None
None
.block { ... } .block--modifier { ... } .block__element {
... } .block__element--modifier { ... }
樣式原⼦子化 Atomic CSS 也有⼈人稱 functional CSS 物件導向弱掉了了 這年年頭叫 functional 比較潮
Good Bad
None
None
None
新需求
新需求 - 2
None
新需求 - 3
吾⽣生有涯 ⽽而需求無涯 - 莊⼦子 沒有說過
None
Thinking in Atomic • 變化是可被預測的 - Changes are predictable •
作⽤用範圍有限 - Scope is limited • 精簡的 CSS - CSS is lean • 與元件解耦 - Components are portable • 初學者易易上⼿手 - Beginner-friendly
⼤大 Component 時代 CSS Module、CSS in JS、scoped styles …
None
• CSS Modules,透過 webpack 編譯 • 各種 CSS in JS
解決⽅方案 ( React ) • 寫在 .vue file 中的 scoped CSS • Angular 裝飾⼦子的 CSS • 現代的關注點分離 - 從功能到元件
HTML Script Style .vue file
CSS Modules in Vue
None
None
Scoped Style
None
None
結論
語意 vs 樣式
肥 CSS 還是肥 HTML
關注點分離的昨是今非
選擇來來⾃自經驗的累積 所有⽅方法的背後都有個難解的問題
⽅方法無分好壞 沒有絕對答案
適合你的才是正姐 正解
⼈人⽣生⽽而⾃自由, 卻無往不在枷鎖之中 - 盧梭
None
CSS 很⾃自由 享受⾃自由要有更更⾼高的⾃自律律
資源推薦 & 友情⼯工商
https://cssguidelin.es/
https://csswizardry.com/
https://www.youtube.com/user/AmosLee1
https://www.hexschool.com/courses/sass.html
下期預告 v-tw meetup 七⽉月份活動,時間地點未定
Thanks