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
Lean Machine
September 05, 2013
Programming
970
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
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
200
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
160
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
450
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
290
霧の中の代数的エフェクト
funnyycat
1
230
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
1.1k
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
7
1.6k
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
200
Performance Engineering for Everyone
elenatanasoiu
0
260
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.7k
symfony/aiとlaravel/boost
77web
0
120
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Discover your Explorer Soul
emna__ayadi
2
1.2k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
630
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
230
Code Reviewing Like a Champion
maltzj
528
40k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
410
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
210
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
220
Visualization
eitanlees
152
17k
Producing Creativity
orderedlist
PRO
348
40k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
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