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
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.4k
Claspは野良GASの夢をみるか
takter00
0
200
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
180
New "Type" system on PicoRuby
pocke
1
980
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
540
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
200
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
ふつうのFeature Flag実践入門
irof
8
4.1k
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
280
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
How GitHub (no longer) Works
holman
316
150k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
260
Marketing to machines
jonoalderson
1
5.5k
The Cult of Friendly URLs
andyhume
79
6.9k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
WENDY [Excerpt]
tessaabrams
11
38k
We Have a Design System, Now What?
morganepeng
55
8.2k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.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