-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-CSS Selectors & Specificity.html
More file actions
185 lines (142 loc) · 3.37 KB
/
03-CSS Selectors & Specificity.html
File metadata and controls
185 lines (142 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Selectors & Specificity – JDCodebase</title>
<style>
/* ---------------------------
BASIC SELECTORS
----------------------------*/
p {
color: red;
}
.info {
color: blue;
}
#box {
background: black;
color: white;
padding: 10px;
}
/* Universal Selector */
* {
font-family: Arial, Helvetica, sans-serif;
}
/* Grouping Selector */
h1,
h2 {
color: green;
}
/* Descendant Selector */
.container p {
color: purple;
}
/* Child Selector */
.container > p {
color: orange;
font-weight: bold;
}
/* Sibling Selectors */
h3 + p {
color: brown;
}
h3 ~ p {
background: #e6e6e6;
}
/* Attribute Selector */
input[type="text"] {
border: 2px solid blue;
padding: 5px;
}
a[target="_blank"] {
color: green;
}
/* Pseudo Classes */
a:hover {
color: red;
}
input:focus {
border: 2px solid green;
outline: none;
}
li:first-child {
color: blue;
}
li:last-child {
color: darkorange;
}
/* ---------------------------
SPECIFICITY EXAMPLE
----------------------------*/
p {
color: red;
}
.parent p {
color: blue;
}
#special p {
color: green;
}
/* !important Example */
.important-text {
color: purple !important;
}
</style>
</head>
<body>
<h1>CSS Selectors & Specificity</h1>
<h2>JDCodebase Web Development Series</h2>
<hr />
<!-- BASIC SELECTORS -->
<h2>Basic Selectors</h2>
<p>This is a normal paragraph (element selector)</p>
<p class="info">This paragraph uses a class selector</p>
<div id="box">This div uses an ID selector</div>
<hr />
<!-- DESCENDANT & CHILD -->
<h2>Descendant & Child Selectors</h2>
<div class="container">
<p>Direct child paragraph</p>
<section>
<p>Nested paragraph (descendant)</p>
</section>
</div>
<p>Outside paragraph</p>
<hr />
<!-- SIBLINGS -->
<h2>Sibling Selectors</h2>
<h3>Heading 3</h3>
<p>Adjacent sibling paragraph</p>
<p>General sibling paragraph</p>
<hr />
<!-- ATTRIBUTE SELECTORS -->
<h2>Attribute Selectors</h2>
<input type="text" placeholder="Type here..." />
<br /><br />
<a href="#" target="_blank">Open in new tab</a>
<hr />
<!-- PSEUDO CLASSES -->
<h2>Pseudo Class Selectors</h2>
<a href="#">Hover on this link</a>
<br /><br />
<input type="text" placeholder="Click to focus" />
<ul>
<li>First Item</li>
<li>Middle Item</li>
<li>Last Item</li>
</ul>
<hr />
<!-- SPECIFICITY -->
<h2>Specificity Example</h2>
<div class="parent">
<div id="special">
<p>This paragraph is affected by multiple selectors</p>
</div>
</div>
<p class="important-text">This text uses !important</p>
<hr />
<h2>End of Demo</h2>
<p>Practice and experiment to understand better!</p>
</body>
</html>