forked from wesbos/hot-tips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
css-nesting.html
101 lines (99 loc) · 2.61 KB
/
css-nesting.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Nesting Selectors</title>
</head>
<body>
<div class="container">
<h2>CSS Nesting Selectors</h2>
<p class="text">Pretty cool</p>
<p class="special">Very Special</p>
<p class="special">ALso special</p>
<div class="special">
<div class="special">
<div class="special">
<div class="special">
<div class="special">
<div class="special">
<div class="special">
<div class="special">
<div class="special">
<div class="special">10 level deep</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="https://wesbos.com">WesBos.com</a>
<a href="https://google.com">google.com</a>
<a href="https://google.com"><span>google</span><span>.</span>com</a>
</div>
<style>
.container {
border: 1px solid red;
container: article / inline-size;
/* Nested Selectors */
.text {
font-size: 100px;
}
/* & matches the parent selector */
/* Same as above */
& .special {
color: red;
/* .special + .special */
& + & {
border: 1px solid blue;
}
/* 10 levels deep of the .special */
& & & & & & & & & & {
background: red;
}
}
/* Nesting Element Selectors - must use &*/
& a {
color: red;
/* Nesting Pseudo Selectors */
&:hover {
color: green;
}
/* Compound */
&[href*="wesbos"],
&:is(.special),
&:has(img) {
color: blue;
}
/* Descendant Selectors */
> span {
background: purple;
+ span {
background: orange;
}
}
}
/* Siblings */
/* Media Queries */
@media (max-width: 600px) {
border-color: blue;
.text {
font-size: 50px;
}
}
& p {
/* Container Queries */
@container (max-width: 600px) {
background: blue;
}
}
resize: both;
overflow: hidden;
}
/* use PostCSS Nesting Plugin to use today */
</style>
</body>
</html>