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
0
25
CSS Specificity
Matija Marohnić
October 09, 2020
Tweet
Share
More Decks by Matija Marohnić
See All by Matija Marohnić
Introduction to Remix
silvenon
0
130
Cypress vs. Playwright
silvenon
0
150
Studying Strapi: an open source head headless CMS
silvenon
0
33
Make your JavaScript projects more accessible to newcomers
silvenon
0
69
React Hooks
silvenon
0
67
PostCSS
silvenon
0
41
CSS Custom Properties
silvenon
0
37
Maintainable Integration Testing in React
silvenon
0
28
Writing Codemods with jscodeshift
silvenon
0
26
Other Decks in Programming
See All in Programming
Ruby on Railroad: The Power of Visualizing CFG
ydah
0
300
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
generative-ai-use-cases(GenU)の推しポイント ~2025年4月版~
hideg
1
380
KANNA Android の技術的課題と取り組み
watabee
0
200
サービスレベルを管理してアジャイルを加速しよう!! / slm-accelerate-agility
tomoyakitaura
1
200
The Nature of Complexity in John Ousterhout’s Philosophy of Software Design
philipschwarz
PRO
0
160
ニーリーQAのこれまでとこれから
nealle
2
500
20250426 GDGoC 合同新歓 - GDGoC のススメ
getty708
0
110
プロダクト横断分析に役立つ、事前集計しないサマリーテーブル設計
hanon52_
3
550
Thank you <💅>, What's the Next?
ahoxa
1
590
AI時代の開発者評価について
ayumuu
0
230
fieldalignmentから見るGoの構造体
kuro_kurorrr
0
130
Featured
See All Featured
Become a Pro
speakerdeck
PRO
28
5.3k
Code Review Best Practice
trishagee
67
18k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
120
52k
A designer walks into a library…
pauljervisheath
205
24k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
How STYLIGHT went responsive
nonsquared
100
5.5k
Unsuck your backbone
ammeep
671
57k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Docker and Python
trallard
44
3.4k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Practical Orchestrator
shlominoach
187
11k
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
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!