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
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
5
9.3k
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
16
6k
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
1
220
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
210
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
980
Hack Claude Code with Claude Code
choplin
8
2.8k
テスト環境にCDを導入してみた
yasaigaoisi
0
100
AIともっと楽するE2Eテスト
myohei
9
3.1k
Claude Code派?Gemini CLI派? みんなで比較LT会!_20250716
junholee
1
690
CIを整備してメンテナンスを生成AIに任せる
hazumirr
0
190
Claude Code で Astro blog を Pages から Workers へ移行してみた
codehex
0
140
AI時代の『改訂新版 良いコード/悪いコードで学ぶ設計入門』 / ai-good-code-bad-code
minodriven
24
10k
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Embracing the Ebb and Flow
colly
86
4.8k
GraphQLとの向き合い方2022年版
quramy
49
14k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Fireside Chat
paigeccino
37
3.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
21
1.3k
It's Worth the Effort
3n
185
28k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
282
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
4 Signs Your Business is Dying
shpigford
184
22k
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