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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Lean Machine
September 05, 2013
Programming
960
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Organizing Stylesheets with CSS Pre-processors
Lean Machine
September 05, 2013
More Decks by Lean Machine
See All by Lean Machine
Graceful Degradation with Modernizr
leanmachine
1
1k
Intro to HTML5
leanmachine
3
990
Responsive Web Design in a Nutshell
leanmachine
3
140
Seven UX Design Rules
leanmachine
9
1k
JavaScript Closures
leanmachine
1
1.1k
JavaScript Inheritance
leanmachine
2
1.1k
Asynchronous JavaScript
leanmachine
1
970
JavaScript Promises
leanmachine
2
1.1k
Other Decks in Programming
See All in Programming
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
230
OSもどきOS
arkw
0
560
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
170
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
Vite+ Unified Toolchain for the Web
naokihaba
0
300
RTSPクライアントを自作してみた話
simotin13
0
600
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
130
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
Lessons from Spec-Driven Development
simas
PRO
0
190
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
Oxcを導入して開発体験が向上した話
yug1224
4
310
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
240
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
21k
Chasing Engaging Ingredients in Design
codingconduct
0
220
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
230
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
The Invisible Side of Design
smashingmag
302
52k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
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