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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Matija Marohnić
October 09, 2020
Programming
0
47
CSS Specificity
Matija Marohnić
October 09, 2020
Tweet
Share
More Decks by Matija Marohnić
See All by Matija Marohnić
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
10
Introduction to Remix
silvenon
0
150
Cypress vs. Playwright
silvenon
0
170
Studying Strapi: an open source head headless CMS
silvenon
0
49
Make your JavaScript projects more accessible to newcomers
silvenon
0
80
React Hooks
silvenon
0
85
PostCSS
silvenon
0
46
CSS Custom Properties
silvenon
0
43
Maintainable Integration Testing in React
silvenon
0
50
Other Decks in Programming
See All in Programming
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
220
Raku Raku Notion 20260128
hareyakayuruyaka
0
420
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
380
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
110
AI活用のコスパを最大化する方法
ochtum
0
110
個人開発は儲からない - それでも開発開始1ヶ月で300万円売り上げた方法
taishiyade
0
120
CSC307 Lecture 09
javiergs
PRO
1
850
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
360
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
280
atmaCup #23でAIコーディングを活用した話
ml_bear
4
700
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
2
170
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
1
320
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
460
Designing for Performance
lara
611
70k
We Have a Design System, Now What?
morganepeng
55
8k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
810
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Designing for Timeless Needs
cassininazir
0
140
Exploring anti-patterns in Rails
aemeredith
2
280
エンジニアに許された特別な時間の終わり
watany
106
230k
Building an army of robots
kneath
306
46k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
130
Thoughts on Productivity
jonyablonski
75
5.1k
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!