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
36
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
29
Introduction to Remix
silvenon
0
170
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
97
React Hooks
silvenon
0
98
PostCSS
silvenon
0
67
CSS Custom Properties
silvenon
0
59
Other Decks in Programming
See All in Programming
Cloudflare is Agents
chimame
0
180
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
110
MySQLとPostgreSQLって何が違うの?
akagami
0
150
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
160
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.3k
高専キャリア LT 発表内容
crysta1221
4
4.3k
ソフトウェアラスタライザ
fadis
1
720
リアルな遅延を測る仕様
kota_yata
1
130
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
5
1.8k
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
180
T3DD26: From RAGs to Riches
martinhelmich
0
110
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
3
2.3k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
58k
Design in an AI World
tapps
1
290
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
380
エンジニアに許された特別な時間の終わり
watany
108
250k
Mind Mapping
helmedeiros
PRO
1
340
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
For a Future-Friendly Web
brad_frost
183
10k
Rails Girls Zürich Keynote
gr2m
96
14k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
670
Raft: Consensus for Rubyists
vanstee
141
7.7k
How to build a perfect <img>
jonoalderson
1
5.9k
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!