-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSS-sibling-selectors.html
69 lines (64 loc) · 1.74 KB
/
CSS-sibling-selectors.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Sibling Selectors</title>
<style>
/* The adjacent sibling selector */
p+p {
margin: 0;
color: aqua;
}
h2+p {
margin: 0;
color: aqua;
}
img+span {
margin-left: 120px;
}
/*General sibling selector */
h2~p{
color: blue;
background-color: coral;
}
</style>
</head>
<body>
<h1>The adjacent sibling selector</h1>
<p>
the adjacent sibling selector h2 + p only p elements directly following
after h2 elements will be selected. Both of which must also share the same
parent element.
</p>
<div>
<p>I'm a paragraph</p>
<p>I get selected!</p>
<h2>Work</h2>
<p>working</p>
<h5>work</h5>
<p>not working</p>
<h2>Work</h2>
<p>working</p>
<img src="img/arrow.png" alt="" />
<span>Demo TExt</span>
<!-- p+p=> The plus sign (+) is the adjacent sibling combinator, between two paragraph tag (element) selectors. What this means is “select any paragraph tag that is directly after another paragraph tag (with nothing in between)”. -->
</div>
<hr>
<hr>
<h1>General sibling selector</h1>
<div>
<p>I'm a paragraph</p>
<p>I get selected!</p>
<h2>Work</h2>
<p>working</p>
<h5>work</h5>
<p>not working</p>
<h2>Work</h2>
<p>working</p>
<img src="img/arrow.png" alt="" />
<span>Demo TExt</span>
<p>worked</p>
</div>
</body>
</html>