-
Notifications
You must be signed in to change notification settings - Fork 5
/
css-container-queries.html
129 lines (113 loc) · 2.49 KB
/
css-container-queries.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
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
<!DOCTYPE html>
<title>CSS container queries</title>
<style>
.container-both {
contain: size layout style;
border: 2px solid darkslategrey;
width: 300px;
animation: 8s infinite alternate heighten linear;
}
.container-single-axis {
border: 2px solid darkslateblue;
margin: 2vw;
}
.inline-size {
contain: inline-size layout style;
animation: 8s infinite alternate widen linear;
}
.block-size {
contain: block-size layout style;
animation: 8s infinite alternate heighten linear;
}
@keyframes widen {
from {
width: 300px;
}
to {
width: 1000px;
}
}
@keyframes heighten {
from {
height: 100px;
}
to {
height: 500px;
}
}
.item, .item-aspect-ratio {
display: inline-block;
margin: 10px;
width: 200px;
height: 200px;
}
.inline-size .item {
width: 30%;
}
.block-size .item {
height: 30%;
}
@container (max-width: 600px) {
.item {
height: 100px;
background-color: sandybrown;
}
}
@container (min-width: 601px) and (max-width: 900px) {
.item {
height: 300px;
background-color: olivedrab;
}
}
@container (min-width: 901px) {
.item {
height: 500px;
background-color: cadetblue;
}
}
@container (max-height: 200px) {
.item {
width: 100px;
background-color: sandybrown;
}
}
@container (min-height: 201px) and (max-height: 400px) {
.item {
width: 300px;
background-color: olivedrab;
}
}
@container (min-height: 401px) {
.item {
display: block;
width: 500px;
background-color: cadetblue;
}
}
@container (max-aspect-ratio: 1 / 1) {
.item-aspect-ratio {
background-color: green;
}
}
@container (min-aspect-ratio: 1 / 1) {
.item-aspect-ratio {
background-color: orange;
}
}
</style>
<p>Inline-size container: boxes change color and height at different width thresholds [600, 900]</p>
<div class="container-single-axis inline-size">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<p>Block-size container: boxes change color and width at different height thresholds [200, 400]</p>
<div class="container-single-axis block-size">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<p>Size container: box changes color at before and after aspect-ratio 1:1</p>
<div class="container-both">
<div class="item-aspect-ratio"></div>
</div>