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
Pattern Placeholders
Search
Jaime Caballero
January 21, 2015
Programming
3
66
Pattern Placeholders
Thinking about the ways of using @extend and placeholders.
Jaime Caballero
January 21, 2015
Tweet
Share
Other Decks in Programming
See All in Programming
新しいモバイルアプリ勉強会(仮)について
uetyo
1
250
What's new in Adaptive Android development
fornewid
0
140
202507_ADKで始めるエージェント開発の基本 〜デモを通じて紹介〜(奥田りさ)The Basics of Agent Development with ADK — A Demo-Focused Introduction
risatube
PRO
6
1.4k
SwiftでMCPサーバーを作ろう!
giginet
PRO
2
230
Gemini CLIの"強み"を知る! Gemini CLIとClaude Codeを比較してみた!
kotahisafuru
3
970
CEDEC2025 長期運営ゲームをあと10年続けるための0から始める自動テスト ~4000項目を50%自動化し、月1→毎日実行にした3年間~
akatsukigames_tech
0
120
JetBrainsのAI機能の紹介 #jjug
yusuke
0
200
Strands Agents で実現する名刺解析アーキテクチャ
omiya0555
1
120
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
2
440
decksh - a little language for decks
ajstarks
4
21k
AIに安心して任せるためにTypeScriptで一意な型を作ろう
arfes0e2b3c
0
340
Flutterと Vibe Coding で個人開発!
hyshu
1
250
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
25
1.8k
How STYLIGHT went responsive
nonsquared
100
5.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
How to Ace a Technical Interview
jacobian
278
23k
Designing for humans not robots
tammielis
253
25k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Into the Great Unknown - MozCon
thekraken
40
2k
Code Reviewing Like a Champion
maltzj
524
40k
Raft: Consensus for Rubyists
vanstee
140
7.1k
BBQ
matthewcrist
89
9.8k
Transcript
%Pattern Placeholders Jaime Caballero - LDN Sass #2 GIF Source:
giphy.com 21/01/2015
None
hi, I’m jaime
jamie james jiame jaime
None
None
• spanish • frontend architect • sass lover
None
None
None
this is me when I’m using Sass
None
this is me when somebody hands me over vanilla CSS
None
me gusta • SMACSS • OOCSS • DRYCSS • BEM
I worry a lot about keeping my CSS scalable and
organised
this is me going through my CSS workflow
None
let’s talk about @extend 1.
@extend combines selectors
.foo
.foo{ color: black; }
.another
.another{ color: black; }
.another{ @extend .foo; }
.another{ @extend .foo; background: white; }
.foo, .another{ color: black; } .another{ background: white; }
combining selectors means no repeating CSS chunks
this is me when I discovered @extend
None
BUT!
we can’t extend without a selector, can we?
.foo{ color: black; }
None
introducing placeholder selectors 2.
if you don’t @extend them, they will not be in
the CSS
.foo
%foo
%foo{ color: black; }
you can have anything in one place, ready to use
BUT!
i’m not here to say @extend FTW
None
all this has its limitations
you can’t extend in a @media query
%foo{ color: black; } @media (min-width: 20em){ .another{ @extend %foo;
} }
you can easily get loads of selectors
a.icon-listen-bl:hover, .event-related .box-title a:hover, .category-related .box-title a:hover, .readmore a:hover, .footer
a:hover, .pagination a:hover, .news a:hover, .latest-tweet .date a:hover, .feature .box-header .title a:hover, .caption .title a:hover, .full-agenda-link a:hover,
that was 46 selectors for 1 property
i like to call this aggressive extending
this is me when i see any of it
None
we are the problem 3.
people are complaining
None
BUT!
we are the ones extending the wrong way
we have to think outside the box
embrace these limitations
you can’t extend in a @media query?
but you can put a media query in a placeholder
%foo{ color: black; } @media (min-width: 20em){ .another{ @extend .foo;
} }
%foo{ }
%foo{ @media (min-width: 20em){ } }
%foo{ @media (min-width: 20em){ color: black; } }
%foo{ @media (min-width: 20em){ color: black; } } .another{ @extend
%foo; }
@media (min-width: 20em){ .another{ color: black; } }
implement placeholder patterns
%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{ @extend %nav-fixed; }
%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{ @extend %nav-offcanvas; }
%nav-fixed{…} %nav-offcanvas{…} %nav-footeranch{…} .nav{ @extend %nav-footeranch; }
placeholders for everything
%foo{…} %foo--good{…} %foo--bad{…}
combine them
.Foo.is-good{ @extend %foo; @extend %foo--good; }
separate them
.Foo{ @extend %foo; } .is-good{ @extend %foo--good; }
BEM? SUITCSS? whatever works
None
placeholder patterns add another abstraction layer
you can create naming-agnostic CSS systems
when you only use placeholders
it’s easier to notice a repeated/wrong pattern
.button--action{ @extend %btn; @extend %btn--big; @extend %bg--green; }
BUT!
what about agressive extending ?
agressive extending: fixed 4.
what if we could limit the amount of selectors
?
None
actually, we need to set a selector budget
a warning when we don’t extend properly
a weekend after (last weekend)
this is me after last weekend
None
jaicab.com/ext/
the ext(); mixin sets a selector budget and warns you
(@warn) when you are:
extending too much
extending the same pair (selector, placeholder) more than once
extending twice doesn’t affect your CSS, but it is a
bad organisation practise
this is how it works
&
html, .foo, .another
$selectors: &;
getting started
bower install ext
@import the _ext.scss file into your project
set your selector budget
$ext-budget: ( total: 15 );
it only works with placeholders
use ext(placeholder);
%foo{ color: black; } .another{ @include ext(foo); }
go nuts!
None
None
is @warn not enough?
enable debug mode
add ext-debug(); after all your @imports
None
None
set a targeted budget
$ext-budget: ( total: 15, heading: 12 );
want to see more? change the options
$ext-options: ( warn-over: true, warn-duplicates: true, over-only: true, show-all: true
);
None
there’s much more
but enough for today
None
go to github.com/jaicab/ext/
None
play with it open an issue send me a pull
request fire me a tweet
thank you! jaicab.com/ext/ @jaicab_ Links: http://bit.ly/1JeTmtr