Cascade
Introduction
How CSS works | MDN
Render-tree | Google
Conflicting rules
Importance
Normal vs Important
Normal | Important |
---|---|
|
|
What is the color of
<h1>
Element?
Style sheet (User Agent, Author, User)
User Agent Style Sheet | Author Style Sheet | User Style Sheet |
---|---|---|
Firefox (Gecko) Safari (WebKit) Chrome (Blink) Microsoft Edge (EdgeHTML) |
style <style> <link> |
Stylish Plugin (Gallery) Stylus Plugin |
Reset CSS: revert.css, normalize.css
Importance order
Declaration | Style sheets | Importance degree |
---|---|---|
User Agent | 1 | |
Normal | User | 2 |
Normal | Author | 3 |
Important | Author | 4 |
Important | User | 5 |
Specificity
Specificity Value
Value: NNNN
Number | Selector |
---|---|
Thousands | style attribute |
Hundreds | ID selector |
Tens | class selector, attribute selector, pseudo-class |
Ones | element selector, pseudo-element |
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="css/style.css" />
<style>
h1 {
color: blue;
}
#title {
color: orange;
}
</style>
</head>
<body>
<h1 id="title" style="color: green;">Lorem ipsum</h1>
</body>
</html>
h1 {
color: red;
}
What is the color of
<h1>
Element?
Style | Selector | Thousands | Hundreds | Tens | Ones | Total |
---|---|---|---|---|---|---|
color: green | style |
1 | 0 | 0 | 0 | 1000 |
color: orange | #title |
0 | 1 | 0 | 0 | 0100 |
color: blue | h1 |
0 | 0 | 0 | 1 | 0001 |
color: red | h1 |
0 | 0 | 0 | 1 | 0001 |
Is it possible to inspect specificity?
If you disable the color green and orange, what is the<h1>
color?
https://i.imgflip.com/2a3ggp.jpg
Source order
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="css/style.css" />
<style>
h1 {
color: blue;
}
body {
color: orange;
}
</style>
</head>
<body>
<h1>Lorem ipsum</h1>
</body>
</html>
h1 {
color: red;
}
What is the color of
<h1>
Element?