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
62
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
29
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
19
Introduction to Remix
silvenon
0
160
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
90
React Hooks
silvenon
0
93
PostCSS
silvenon
0
65
CSS Custom Properties
silvenon
0
52
Other Decks in Programming
See All in Programming
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
11k
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
680
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
350
関係性から理解する"同一性"の型用語たち
pvcresin
2
630
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
420
柔軟なPDFレイアウトエディタを支える型システム設計 — Discriminated UnionとConditional Typeの実践
minako__ph
4
1.3k
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
3k
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
700
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
270
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
270
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
5.2k
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
590
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
180
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
680
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
Odyssey Design
rkendrick25
PRO
2
670
Exploring anti-patterns in Rails
aemeredith
3
380
Done Done
chrislema
186
16k
Speed Design
sergeychernyshev
33
1.8k
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!