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
57
0
Share
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
27
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
16
Introduction to Remix
silvenon
0
150
Cypress vs. Playwright
silvenon
0
170
Studying Strapi: an open source head headless CMS
silvenon
0
55
Make your JavaScript projects more accessible to newcomers
silvenon
0
87
React Hooks
silvenon
0
91
PostCSS
silvenon
0
59
CSS Custom Properties
silvenon
0
52
Other Decks in Programming
See All in Programming
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
330
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
510
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
160
Firefoxにコントリビューションして得られた学び
ken7253
2
150
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
160
ハーネスエンジニアリングとは?
kinopeee
13
6.5k
実用!Hono RPC2026
yodaka
2
280
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
2
360
Road to RubyKaigi: Play Hard(ware)
makicamel
1
520
Running Swift without an OS
kishikawakatsumi
0
870
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
230
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
6
620
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
180
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
130
Done Done
chrislema
186
16k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.7k
Amusing Abliteration
ianozsvald
1
160
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.7k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
280
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!