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
Organizing Stylesheets with CSS Pre-processors
Search
Erik Frisk
September 05, 2013
Programming
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Organizing Stylesheets with CSS Pre-processors
Erik Frisk
September 05, 2013
More Decks by Erik Frisk
See All by Erik Frisk
Seven UX Design Rules
erikfrisk
10
450
The Science of Design
erikfrisk
3
220
Responsive Web Design in a Nutshell
erikfrisk
0
450
Intro to HTML5
erikfrisk
2
170
Graceful Degradation with Modernizr
erikfrisk
1
170
Customer On-boarding in Practice
erikfrisk
2
140
Other Decks in Programming
See All in Programming
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
280
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
Oxlintのカスタムルールの現況
syumai
6
1.1k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
250
AIで効率化できた業務・日常
ochtum
0
140
3Dシーンの圧縮
fadis
1
770
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
680
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
690
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
240
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
1
250
YesSQL, Process and Tooling at Scale
rocio
174
15k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Optimizing for Happiness
mojombo
378
71k
A Tale of Four Properties
chriscoyier
163
24k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
Paper Plane
katiecoart
PRO
1
51k
Tell your own story through comics
letsgokoyo
1
950
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
970
HDC tutorial
michielstock
2
710
Transcript
CSS Pre-processors Harder, Better, Faster, Stronger leanmachine.se ▪
[email protected]
▪
2013-09-06
CSS is dumb!
CSS is dumb! Not DRY (Don’t Repeat Yourself)
CSS is dumb! Not DRY (Don’t Repeat Yourself) Not Maintainable
CSS is dumb! Not DRY (Don’t Repeat Yourself) Not Maintainable
Not Readable
.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; }
.data-table tr { border: 1px solid green; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: green; }
.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; }
.data-table tr { border: 1px solid green; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: green; } .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } }
BETTER CSS SYNTAX NORMAL CSS COMPILER BROWSER
LESS lesscss.org .data-table { width: 700px; margin: 30px auto; background:
#f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } } Sass sass-lang.com .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } } Stylus learnboost.github.io/stylus .data-table width 700px margin 30px auto background #f8f8f8 tr border 1px solid green td padding 10px &.highlight background green
Nice Features: Nesting Variables Mixins Operations
.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr
{ border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } } Nesting .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; }
.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; }
.data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; } @pink: #E82C64; @pageWidth: 700px; .data-table { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid @pink; td { padding: 10px; &.highlight { background: @pink; } } } } Variables
.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; }
.data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; } @pink: #E82C64; @pageWidth: 700px; .reusable-table() { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins
.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; }
.data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; } @pink: #E82C64; @pageWidth: 700px; .reusable-table() { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins ???
@pink: #E82C64; @pageWidth: 700px; .reusable-table() { width: @pageWidth; margin: 30px
auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins
@pink: #E82C64; @pageWidth: 700px; .reusable-table(@w:700px) { width: @w; margin: 30px
auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins
@pink: #E82C64; @pageWidth: 700px; @lightPink: lighten(@pink, 20%); .data-table { .reusable-table();
tr { border: 1px solid @lightPink; } } Operations
@pink: #E82C64; @pageWidth: 700px; @lightPink: lighten(@pink, 20%); @cellWidth: 200px; @cellPadding:
20px; .data-table { .reusable-table(); tr { border: 1px solid @lightPink; td { width: (@cellWidth - 2*@cellPadding); padding: @cellPadding; } } } Operations
A “Design Pattern” for HTML/CSS using pre-processors
HTML Content + Style
HTML Content CSS Style
HTML Content CSS Style • Can’t create a separate “style
structure”
HTML Content CSS Style • Can’t create a separate “style
structure” • Too many classes pollute HTML with style info
HTML Content CSS Style ?
HTML Content LESS structure.less Mirror HTML structure and tie in
styles LESS mixins.less Styles
HTML Content LESS structure.less Mirror HTML structure and tie in
styles LESS mixins.less Styles LESS reset.less Resets, defaults, variables
Workflow
Server Web server that compiles automatically JS that compiles on
page load App or command line tool
Logo Page 1 Page 2 Page 3 The best thing
since sliced bread in three easy steps. Step 1 Step 2 Step 3 Heading Cupcake ipsum dolor sit amet pie dessert faworki fruitcake. Bear claw cupcake candy. Powder ice cream muffin sweet. Cupcake sugar plum bear claw chupa chups wafer biscuit chocolate cake chocolate bar. Cotton candy sweet roll carrot cake oat cake gingerbread toffee jelly-o chocolate chocolate cake. Tart chocolate lemon drops jelly-o muffin oat cake. Pudding candy canes wypas candy carrot cake. Pastry wypas tiramisu chocolate. Pudding pastry brownie cupcake soufflé. Macaroon muffin danish dessert jujubes
Logo Page 1 Page 2 Page 3 The best thing
since sliced bread in three easy steps. Step 1 Step 2 Step 3 Heading Cupcake ipsum dolor sit amet pie dessert faworki fruitcake. Bear claw cupcake candy. Powder ice cream muffin sweet. Cupcake sugar plum bear claw chupa chups wafer biscuit chocolate cake chocolate bar. Cotton candy sweet roll carrot cake oat cake gingerbread toffee jelly-o chocolate chocolate cake. Tart chocolate lemon drops jelly-o muffin oat cake. Pudding candy canes wypas candy carrot cake. Pastry wypas tiramisu chocolate. Pudding pastry brownie cupcake soufflé. Macaroon muffin danish dessert jujubes Exercise Build out this simple page using LESS and the suggested stylesheet design pattern (structure.less, mixins.less, reset.less).
leanmachine.se ▪
[email protected]
▪ 2013-09-06