forked from newmanix/selectors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
189 lines (165 loc) · 6.44 KB
/
index.html
File metadata and controls
189 lines (165 loc) · 6.44 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
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS Selectors by NAME HERE</title>
<link href="css/pre.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<style>
div#id-div{
background-color:yellow;
}
li.my-list{
background-color: orange;
}
div#new-div, li.new-list{
background-color: blue;
}
ul.my-kids > li{
background-color: green;
}
div.grandkids li{
background-color: red;
}
.add-border{
border: 1px solid #000;
}
.add-background{
background-color: gold;
}
</style>
</head>
<body>
<header>
<h1 class="page-header">CSS Selectors by DANAIT GEBREMEDHIN</h1>
<nav>
<ul>
<li><a href="#id">Id</a></li>
<li><a href="#class">Class</a></li>
<li><a href="#compound">Compound</a></li>
<li><a href="#child">Child</a></li>
<li><a href="#descendant">Descendant</a></li>
<li><a href="#multiple">Multiple</a></li>
</ul>
</nav>
</header>
<p>This page demonstrates how CSS selectors work.</p>
<fieldset>
<legend><a id="id">Id</a></legend>
<p>ids can be applied to only one item on a page</p>
<p>Here's how we hook an id attribute to an element:</p>
<pre><code>id="id-div"</code></pre>
<p>Here's how the CSS is applied to the element:</p>
<pre><code>div#id-div{
background-color:yellow;
}</code></pre>
<p>Here's what it looks like:</p>
<div id="id-div">Inside my-div</div>
</fieldset>
<fieldset>
<legend><a id="class">Class</a></legend>
<p>Classes can be applied to several items on a page</p>
<p>Here's how we hook an class attribute to an element:</p>
<pre><code>class="my-list"</code></pre>
<p>Here's how the CSS is applied to the element:</p>
<pre><code>li.my-list{
background-color:orange;
}</code></pre>
<p>Here's what it looks like:</p>
<div>
<ul>
<li class="my-list">I am inside an li with a class of my-list </li>
<li class="my-list">I am inside an li with a class of my-list </li>
<li class="my-list">I am inside an li with a class of my-list </li>
</ul>
</div>
</fieldset>
<fieldset>
<legend><a id="compound">Compound</a></legend>
<p>Compound selectors allow us to use more than one selector for a set of rules. The selectors must be separated by commas</p>
<p>Here's how the CSS is applied to the element:</p>
<pre><code>div#new-list, li.new-list{
background-color: blue;
}
</code></pre>
<p>Here's what it looks like:</p>
<div id="new-div">I'm inside a new div</div>
<div>
<ul>
<li class="new-list">I am inside an li with a class of new-list </li>
<li class="new-list">I am inside an li with a class of new-list </li>
<li class="new-list">I am inside an li with a class of new-list </li>
</ul>
</div>
</fieldset>
<fieldset>
<legend><a id="child">Child</a></legend>
<p>The child selector allows us to access the element that is immediately inside the current element</p>
<p>Here's how the CSS is applied to the element:</p>
<pre><code>ul.my-kids > li{
background-color: green;
}
</code></pre>
<p>Here's what it looks like:</p>
<div>
<ul class="my-kids">
<li class="new-list">I am inside an li of a child of ul with class of my-kids </li>
<li class="new-list">I am inside an li of a child of ul with class of my-kids </li>
<li class="new-list">I am inside an li of a child of ul with class of my-kids </li>
</ul>
</div>
</fieldset>
<fieldset>
<legend><a id="descendant">Descendant</a></legend>
<p>The descendant selector allows us to hook to an element at any depth inside the current element</p>
<p>Here's how the CSS is applied to the element:</p>
<pre><code>div.grandkids li{
background-color: red;
}
</code></pre>
<p>Here's what it looks like:</p>
<div class="grandkids">
<ul>
<li>I am inside an li of a descendant of a div with a class of grandkids.</li>
<li>I am inside an li of a descendant of a div with a class of grandkids.</li>
<li>I am inside an li of a descendant of a div with a class of grandkids.</li>
</ul>
</div>
</fieldset>
<fieldset>
<legend><a id="multiple">Multiple</a></legend>
<p>We can apply multiple classes by placing them in the class attribute with a space between each</p>
<p>Here's how we hook multiple classes to an element:</p>
<pre><code>class="add-border add-background"</code></pre>
<p>Here's how the CSS is applied to the element:</p>
<pre><code>
.add-border{
border: 1px solid #000;
}
.add-background{
background-color: gold;
}</code></pre>
<p>Here's what it looks like:</p>
<div>
<ul>
<li class="add-border add-background">I am inside an li with two classes </li>
<li class="add-border add-background">I am inside an li with two classes </li>
<li class="add-border add-background">I am inside an li with two classes </li>
</ul>
</div>
</fieldset>
<footer class="page-footer">
<p><small>© 2023 by
DANAIT GEBREMEDHIN, All Rights Reserved ~
<a id="html-checker" href="#" target="_blank">Check HTML</a> ~
<a id="css-checker" href="#" target="_blank">Check CSS</a></small>
</p>
</footer>
<script>
document.getElementById("html-checker").setAttribute("href","https://validator.w3.org/nu/?doc=" + location.href);
document.getElementById("css-checker").setAttribute("href","https://jigsaw.w3.org/css-validator/validator?uri=" + location.href);
</script>
</body>
</html>