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 Re...
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.2k
Styled Components and the Road to Unification
geelen
2
280
The Future of Reusable CSS
geelen
2
200
Other Decks in Technology
See All in Technology
日経電子版におけるリアルタイムレコメンドシステム開発の事例紹介/nikkei-realtime-recommender-system
yng87
1
510
Jr. Championsになって、強く連携しながらAWSをもっと使いたい!~AWSに対する期待と行動~
amixedcolor
0
190
「最高のチューニング」をしないために / hack@delta 24.10
fujiwara3
21
3.4k
プロダクトエンジニアが活躍する環境を作りたくて 事業責任者になった話 ~プロダクトエンジニアの行き着く先~
gimupop
1
480
カメラを用いた店内計測におけるオプトインの仕組みの実現 / ai-optin-camera
cyberagentdevelopers
PRO
1
120
ユーザーの購買行動モデリングとその分析 / dsc-purchase-analysis
cyberagentdevelopers
PRO
2
100
Apple/Google/Amazonの決済システムの違いを踏まえた定期購読課金システムの構築 / abema-billing-system
cyberagentdevelopers
PRO
1
220
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
180
よくわからんサービスについての問い合わせが来たときの強い味方 Amazon Q について
kazzpapa3
0
220
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
170
LeSSに潜む「隠れWF病」とその処方箋
lycorptech_jp
PRO
2
120
プロダクトチームへのSystem Risk Records導入・運用事例の紹介/Introduction and Case Studies on Implementing and Operating System Risk Records for Product Teams
taddy_919
1
170
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
290
Adopting Sorbet at Scale
ufuk
73
9k
Building Adaptive Systems
keathley
38
2.2k
How to train your dragon (web standard)
notwaldorf
88
5.7k
KATA
mclloyd
29
13k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Visualization
eitanlees
144
15k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Writing Fast Ruby
sferik
626
61k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
7.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
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