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 Modules, CSS Variables and the Future of Reusable CSS
Search
Glen Maddern
May 11, 2016
Technology
9
1.2k
CSS Modules, CSS Variables and the Future of Reusable CSS
Presented at CSSConf Budapest, 2016 <3
Glen Maddern
May 11, 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.1k
Styled Components and the Road to Unification
geelen
2
270
The Future of Reusable CSS
geelen
2
200
Other Decks in Technology
See All in Technology
オーナーシップを持つ領域を明確にする
konifar
13
3.2k
EMとして2023年度に頑張ったこと / What we did well in FY2023 as a EM
pauli
1
170
KubeConにproposalを送りたい人へのアドバイス
sat
PRO
3
250
ChatworkのSRE部って実は 半分くらいPlatform Engineering部かもしれない
saramune
0
160
プロトタイピングによる不確実性の低減 / Reducing Uncertainty through Prototyping
ohbarye
5
380
AOAI をきっかけに 社内の Azure 管理を見直した話
recruitengineers
PRO
1
290
プラットフォームってつくることより計測することが重要なんじゃないかという話 / Platform Engineering Meetup #8
taishin
1
360
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
130
よく聞くけど使ったことないソフトウェアNo.1 KafkaとSnowflake
foursue
4
360
生成AIの変革の時代に、直近1年で直面した課題とその解決策
ktc_wada
0
200
DevOpsDays History and my DevOps story
kawaguti
PRO
9
2.5k
Kernel MemoryでAzure OpenAI Serviceとお手軽データソース連携
mitsuzono
1
250
Featured
See All Featured
Thoughts on Productivity
jonyablonski
58
3.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Fireside Chat
paigeccino
21
2.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
24
2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
274
13k
Gamification - CAS2011
davidbonilla
76
4.6k
The Power of CSS Pseudo Elements
geoffreycrofte
60
5k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
Web Components: a chance to create the future
zenorocha
305
41k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Writing Fast Ruby
sferik
621
60k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
Transcript
Reusable CSS CSS VARIABLES, CSS MODULES & THE FUTURE OF
@glenmaddern
HELLO BUDAPEST! ♥
Reusable CSS CSS VARIABLES, CSS MODULES & THE FUTURE OF
@glenmaddern
None
WHY IS IT SO HARD TO SHARE CSS?
WHY IS IT SO HARD TO REUSE CSS?
import something from 'somewhere' something.leftPad()
THE HUMAN BRAIN IS A (IN)CONSISTENCY-DETECTING MACHINE
http://semantic-ui.com
http://semantic-ui.com
http://semantic-ui.com
http://www.novolume.co.uk/blog/all-websites-look-the-same/
http://graphicriver.net/
None
WE DON'T NEED MORE TOOLING TO MAKE OUR CURRENT COMPONENTS
THEMEABLE WE NEED TO START BUILDING BETTER COMPONENTS
st ep #1
RESPONSIVE COMPONENTS
A COMPONENT SHOULD RESPOND TO ITS ENVIRONMENT • • RATHER
THAN THE ENVIRONMENT OVERRIDING THE COMPONENT
OUTSIDE-IN OVERRIDES
https://en.wikipedia.org/wiki/Margaret_Hamilton_(scientist)
http://semantic-ui.com
MAKE YOUR COMPONENTS LESS RESPONSIBLE & MORE RESPONSIVE
layout
PADDING CONTENT MARGIN
PADDING CONTENT MARGIN
.component { width: 50%; margin-top: 2rem; flex-grow: 1; } ❌
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } ONE ONE TWO ONE TWO THREE
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } .parent > * + * { margin-left: 1rem; } ONE ONE TWO ONE TWO THREE
.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
LAYOUT IS THE CONCERN OF THE p arent
DEMO: CURRENTCOLOR
https://www.youtube.com/watch?v=jPOBVaomzLE
css v ari able s
http://caniuse.com/#feat=css-variables
CSS CUSTOM PROPERTIES CSS VARIABLES =
.component { --size: 2rem; width: calc(2 * var(--size)); height: var(--size);
} .component
.component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:
var(--size); } .component .container .component .container { --spacing: 1rem; }
.component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:
var(--size); } .component .component.large .large { --spacing: 4rem; /* or */ --size: 4rem; }
.component { background: var(--bg, black); color: var(--fg, white); }
.component { background: var(--bg, black); color: var(--fg, white); } (bg,
fg) => <Component style.../>
DEMO: INVERTED BUTTON
INHERITANCE THE CASCADE vs
st ep #2
EXPLICIT COMPONENTS
http://semantic-ui.com/elements/button.html
http://jxnblk.com/rebass/#Button
DEMO: DOCUMENTATION
NAMING MISMATCHES?
.container .container { --grid-size: 1rem; } .component .component .component {
--size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
.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); }
st ep #3
RESILIENT COMPONENTS
w arning: re act
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> )
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
DEMO: INTERNAL STRUCTURE DOCS
✅ RESPOND TO ENVIRONMENT ✅ USE INTERNAL VARIABLES ✅ EXPOSE
INTERNAL STRUCTURE
t hank you! @glenmaddern