EN
CSS - :not pseudo-class
0 points
In this article, we would like to show you :not
pseudo-class example in CSS.
Quick solution:
xxxxxxxxxx
1
:not(div) {
2
color: red;
3
}
In this example, we change the font color of all elements that are not div
elements using :not
pseudo-class.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div {
7
color: black;
8
}
9
10
:not(div) {
11
color: red;
12
}
13
14
</style>
15
</head>
16
<body>
17
<div>div element</div>
18
<p>p element</p>
19
<h3>h3 element</h3>
20
<h2>h2 element</h2>
21
</body>
22
</html>
To include multiple elements with :not
pseudo-class you can specify them inside the brackets separated by a comma.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div {
7
color: black;
8
}
9
10
p {
11
color: blue;
12
}
13
14
:not(div, p) {
15
color: red;
16
}
17
18
</style>
19
</head>
20
<body>
21
<div>div element</div>
22
<p>p element</p>
23
<h3>h3 element</h3>
24
<h2>h2 element</h2>
25
<ul>Unordered List:
26
<li>li element</li>
27
<li>li element</li>
28
</ul>
29
<ol>Ordered List:
30
<li>li element</li>
31
<li>li element</li>
32
</ol>
33
</body>
34
</html>