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
CSS Specificity
Search
Matija Marohnić
October 09, 2020
Programming
64
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSS Specificity
Matija Marohnić
October 09, 2020
More Decks by Matija Marohnić
See All by Matija Marohnić
oxlint & oxfmt: linting and formatting from the future
silvenon
0
31
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
25
Introduction to Remix
silvenon
0
160
Cypress vs. Playwright
silvenon
0
180
Studying Strapi: an open source head headless CMS
silvenon
0
58
Make your JavaScript projects more accessible to newcomers
silvenon
0
93
React Hooks
silvenon
0
98
PostCSS
silvenon
0
66
CSS Custom Properties
silvenon
0
56
Other Decks in Programming
See All in Programming
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
160
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.4k
源内ハンズオン概要編
hideg
0
130
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
180
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
590
VibeCodingからAgenticWorkflowへ
starfish719
0
330
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
150
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
210
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
450
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
200
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
430
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
How GitHub (no longer) Works
holman
316
150k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The SEO Collaboration Effect
kristinabergwall1
1
520
Code Reviewing Like a Champion
maltzj
528
40k
The browser strikes back
jonoalderson
0
1.5k
Documentation Writing (for coders)
carmenintech
77
5.4k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Transcript
Matija Marohnić CSS Specificity
A little bit about me • frontend developer and blogger
• obsessed with generating static sites • DX evangelist • open source • automate all the things • follow me on Twitter: @silvenon
MDN Web docs “Specificity is the means by which browsers
decide which property values are the most relevant to an element and, therefore, will be applied.”
X Y Z type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 0 1 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 1 2 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
1 2 2 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 54 0 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors A trick to bump specificity
0 1 0 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
• these don’t affect specificity: • universal selector (*) •
combinators (+, >, ~, etc.) • negation pseudo-class (:not())
0 0 0 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 1 1 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
1 0 0 0 type selectors, pseudo-elements class selectors, attribute
selectors, pseudo-classes ID selectors inline style
1 0 0 0 1 type selectors, pseudo-elements class selectors,
attribute selectors, pseudo-classes ID selectors inline style !important
When to use !important • as little as possible •
basically only to override third-party styles
An alternative to !important Lorem ipsum dolor, sit amet consectetur
adipisicing elit.
The best way to increase specificity is…
• the lower the specificity, the easier it is to
manage • plus, this way we keep repetition out of HTML …source order.
The color of the paragraph is: 1. red 2. green
3. blue 4. fuchsia Quiz!
Happy styling!