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
21
CSS Specificity
Matija Marohnić
October 09, 2020
Tweet
Share
More Decks by Matija Marohnić
See All by Matija Marohnić
Introduction to Remix
silvenon
0
120
Cypress vs. Playwright
silvenon
0
140
Studying Strapi: an open source head headless CMS
silvenon
0
30
Make your JavaScript projects more accessible to newcomers
silvenon
0
64
React Hooks
silvenon
0
62
PostCSS
silvenon
0
36
CSS Custom Properties
silvenon
0
34
Maintainable Integration Testing in React
silvenon
0
23
Writing Codemods with jscodeshift
silvenon
0
23
Other Decks in Programming
See All in Programming
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
280
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.4k
最近のVS Codeで気になるニュース 2025/01
74th
1
100
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
870
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
770
DMMオンラインサロンアプリのSwift化
hayatan
0
190
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.3k
ASP.NET Core の OpenAPIサポート
h455h1
0
120
functionalなアプローチで動的要素を排除する
ryopeko
1
210
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
1k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
Оптимизируем производительность блока Казначейство
lamodatech
0
950
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Embracing the Ebb and Flow
colly
84
4.5k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Building Your Own Lightsaber
phodgson
104
6.2k
Become a Pro
speakerdeck
PRO
26
5.1k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Bash Introduction
62gerente
610
210k
Mobile First: as difficult as doing things right
swwweet
222
9k
Designing for humans not robots
tammielis
250
25k
Building Adaptive Systems
keathley
38
2.4k
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!