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
The Future of Reusable CSS
Search
Glen Maddern
September 01, 2016
Technology
2
200
The Future of Reusable CSS
Presented at Coldfront Conf 2016 <3
Glen Maddern
September 01, 2016
Tweet
Share
More Decks by Glen Maddern
See All by Glen Maddern
The Road to Styled Components & the Road Ahead
geelen
2
230
The Road to Styled Components
geelen
2
1.2k
Styled Components and the Road to Unification
geelen
2
280
CSS Modules, CSS Variables and the Future of Reusable CSS
geelen
9
1.2k
Other Decks in Technology
See All in Technology
Shift-from-React-to-Vue
calm1205
3
1.3k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
49k
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
27
12k
Autify Company Deck
autifyhq
1
39k
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
310
LeSSに潜む「隠れWF病」とその処方箋
lycorptech_jp
PRO
2
120
日経電子版におけるリアルタイムレコメンドシステム開発の事例紹介/nikkei-realtime-recommender-system
yng87
1
510
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
170
コンテンツを支える 若手ゲームクリエイターの アートディレクションの事例紹介 / cagamefi-game
cyberagentdevelopers
PRO
1
130
カメラを用いた店内計測におけるオプトインの仕組みの実現 / ai-optin-camera
cyberagentdevelopers
PRO
1
120
なんで、私がAWS Heroに!? 〜社外の広い世界に一歩踏み出そう〜
minorun365
PRO
6
1.1k
visionOSでの空間表現実装とImmersive Video表示について / ai-immersive-visionos
cyberagentdevelopers
PRO
1
110
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
38
7k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Building an army of robots
kneath
302
42k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
Building Your Own Lightsaber
phodgson
102
6.1k
Building Applications with DynamoDB
mza
90
6.1k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Transcript
Reusable CSS THE FUTURE OF @glenmaddern
HELLO copeNhagen! ♥
@glenmaddern
@glenmaddern "
@glenmaddern
@glenmaddern front end C E N T E R https://frontend.center
@glenmaddern
@glenmaddern 2015 WHAT MAKES CSS SO HARD TO MAINTAIN?
@glenmaddern demonic CSS
None
@glenmaddern ✅ COMPLICATED SELECTORS CSS ✅ OVERRIDE-HEAVY ✅ NO ISOLATION
✅ !IMPORTANT ✅ END OF FILE ONLY
@glenmaddern
@glenmaddern https:/ /github.com/css-modules/css-modules
@glenmaddern IDEAS TECHNIQUES ✏ TECHNOLOGY
@glenmaddern .selector > header > span {} .foo.bar.baz {} p
{} ❌ .single-really-long-classnames {} ✅
@glenmaddern ✏ .Block {} .Block__Element {} .Block__Element--modifier https:/ /bem.info
@glenmaddern .block {} .element {} .modifier {} https:/ /github.com/css-modules/css-modules
@glenmaddern
@glenmaddern
@glenmaddern 2016 WHAT MAKES CSS SO HARD TO REUSE?
@glenmaddern import something from 'somewhere' something.leftPad()
@glenmaddern THE HUMAN BRAIN IS A (IN)CONSISTENCY-DETECTING MACHINE
@glenmaddern http://semantic-ui.com
@glenmaddern http://semantic-ui.com
@glenmaddern http://semantic-ui.com
@glenmaddern http://www.novolume.co.uk/blog/all-websites-look-the-same/
@glenmaddern SETTINGS.SCSS
@glenmaddern https://en.wikipedia.org/wiki/Margaret_Hamilton_(scientist)
@glenmaddern http://semantic-ui.com
@glenmaddern IDEAS TECHNIQUES ✏ TECHNOLOGY
@glenmaddern css v ari able s
@glenmaddern CSS CUSTOM PROPERTIES CSS VARIABLES =
@glenmaddern http://caniuse.com/#feat=css-variables
@glenmaddern
@glenmaddern re sponsive component s
@glenmaddern DEATH TO PIXEL PERFECTION
@glenmaddern YOUR COMPONENTS SHOULD DEMAND LESS & RESPOND MORE
@glenmaddern A COMPONENT SHOULD RESPOND TO ITS ENVIRONMENT • •
RATHER THAN THE ENVIRONMENT OVERRIDING THE COMPONENT
@glenmaddern LAYOUT COMPONENTS ✏
@glenmaddern PADDING MARGIN SIZE
@glenmaddern .component { width: 50%; margin-top: 2rem; flex-grow: 1; }
❌
@glenmaddern .parent { display: flex; padding: 1rem; } .parent >
* { flex-grow: 1; } ONE ONE TWO ONE TWO THREE
@glenmaddern .parent { display: flex; padding: 1rem; } .parent >
* { flex-grow: 1; } .parent > * + * { margin-left: 1rem; } ONE ONE TWO ONE TWO THREE
@glenmaddern .parent { display: flex; padding: 1rem; } .parent >
* { flex-grow: 1; } .parent > * + * { margin-left: 1rem; } .parent > :first-child { flex: 0 0 50%; } ONE TWO ONE TWO THREE ONE TWO THREE FOUR
@glenmaddern CONTEXTUAL COMPONENTS ✏
@glenmaddern DEMO: CURRENTCOLOR
@glenmaddern https://www.youtube.com/watch?v=jPOBVaomzLE
@glenmaddern .component { --size: 2rem; width: calc(2 * var(--size)); height:
var(--size); } .component
@glenmaddern .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size));
height: var(--size); } .component .container .component .container { --spacing: 1rem; }
@glenmaddern .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size));
height: var(--size); } .component .component.large .large { --spacing: 4rem; /* or */ --size: 4rem; }
@glenmaddern .component { background: var(--bg, black); color: var(--fg, white); }
@glenmaddern .component { background: var(--bg, black); color: var(--fg, white); }
(bg, fg) => <Component style.../>
@glenmaddern DEMO: INVERTED BUTTON
@glenmaddern INHERITANCE THE CASCADE vs
@glenmaddern NAMING MISMATCHES?
@glenmaddern .container .container { --grid-size: 1rem; } .component .component .component
{ --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
@glenmaddern .component .container .component.fix .container { --grid-size: 1rem; } .fix
{ --spacing: var(--grid-size); } .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
@glenmaddern EXPLICIT COMPONENTS ✏
@glenmaddern http://semantic-ui.com/elements/button.html
@glenmaddern http://jxnblk.com/rebass/#Button
@glenmaddern DEMO: DOCUMENTATION
@glenmaddern OPEN COMPONENTS ✏
@glenmaddern import styles from './MediaObject.css' const MediaObject = ({ title,
image, text }) => ( <div className={styles.outer}> <img className={styles.img} src={ image }/> <div className={styles.inner}> <h1 className={styles.h1}>{ title }</h1> <p className={styles.p}>{ text }</p> </div> </div> )
@glenmaddern import styles from './MediaObject.css' const MediaObject = ({ title,
image, text, theme=styles })=>( <div className={theme.outer}> <img className={theme.img} src={ image }/> <div className={theme.inner}> <h1 className={theme.h1}>{ title }</h1> <p className={theme.p}>{ text }</p> </div> </div> ) https://github.com/css-modules/css-modules/issues/147
@glenmaddern DEMO: INTERNAL STRUCTURE DOCS
@glenmaddern re sponsive component s
@glenmaddern ✏ KEEP LAYOUT SEPARATE ✏ RESPOND TO CONTEXT ✏
DOCUMENT ASSUMPTIONS ✏ OPEN FOR MODIFICATION
@glenmaddern t hank you! @glenmaddern