summaryrefslogtreecommitdiff
path: root/Base/res/html/misc/media-queries.html
blob: 07344a6a0d3bc8979d5b7c4377ad91df90dc000a (plain)
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
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Media queries</title>
    <style>
        p {
            border: 1px solid black;
            background-color: red;
        }

        .negative {
            background-color: lime;
        }

        @media not all {
            .negative {
                background-color: red !important;
            }
        }

        @media print {
            .negative {
                border: 5px solid magenta !important;
            }
        }

        @media huh {
            .negative {
                color: yellow;
            }
        }

        @media screen {
            .screen {
                background-color: lime;
            }
        }

        @media only all and (min-width: 400px) {
            .size-min {
                background-color: lime;
            }
        }

        @media only all and (width > 399px) {
            .size-min-range {
                background-color: lime;
            }
        }

        @media (max-width: 1000px) {
            .size-max {
                background-color: lime;
            }
        }

        @media (1001px > width) {
            .size-max-range {
                background-color: lime;
            }
        }

        @media (min-width: 400px) and (max-width: 1000px) {
            .size-range {
                background-color: lime;
            }
        }

        @media (400px <= width <= 1000px) {
            .size-range-syntax {
                background-color: lime;
            }
        }

        @media (color) {
            .color {
                background-color: lime;
            }
        }

        @media (not (not (color))) {
            .color-2 {
                background-color: lime;
            }
        }

        @media (color) or ((color) and ((color) or (color) or (not (color)))) {
            .deeply-nested {
                background-color: lime;
            }
        }

        @media (width >= 80em) {
            .em {
                background-color: lime;
            }
        }

        @media (width < 100vh) {
            .viewport {
                background-color: lime;
            }
        }

        @media (aspect-ratio < 4 / 3) {
            .aspect-ratio {
                background-color: lime;
            }
        }
        @media (aspect-ratio >= 2) {
            .aspect-ratio-integer {
                background-color: lime;
            }
        }
        @media (aspect-ratio < 0.5) {
            .aspect-ratio-decimal {
                background-color: lime;
            }
        }
    </style>
</head>
<body>
    <div id="interactive">
        I don't know how wide the page is. <code>window.matchMedia("(min-width: 800px)")</code> is not working. :^(
    </div>
    <p class="negative">
        This should be green if we are correctly ignoring <code>@media</code> rules that do not apply.
    </p>
    <p class="screen">
        This should be green if we are correctly applying <code>@media screen</code>.
    </p>
    <p class="size-min">
        This should be green if the window is at least 400px wide.
    </p>
    <p class="size-min-range">
        This should be green if the window is at least 400px wide, and we understand range syntax.
    </p>
    <p class="size-max">
        This should be green if the window is at most 1000px wide.
    </p>
    <p class="size-max-range">
        This should be green if the window is at most 1000px wide, and we understand range syntax.
    </p>
    <p class="size-range">
        This should be green if the window is between 400px and 1000px wide.
    </p>
    <p class="size-range-syntax">
        This should be green if the window is between 400px and 1000px wide, and we understand range syntax.
    </p>
    <p class="color">
        This should be green if we detected the <code>color</code> feature.
    </p>
    <p class="color-2">
        This should be green if we detected the <code>color</code> feature and we understand <code>not</code>.
    </p>
    <p class="color-2">
        This should be green if we detected the <code>color</code> feature and a deeply nested query: <code>(color) or ((color) and ((color) or (color) or (not (color))))</code>.
    </p>

    <h2>Relative lengths</h2>
    <p class="em">
        This should be green if the window is wider than 80em.
    </p>
    <p class="viewport">
        This should be green if the window is taller than it is wide.
    </p>

    <h2>Ratio</h2>
    <p class="aspect-ratio">
        This should be green if the viewport aspect-ratio is less than 4/3. (So, less wide than a 4:3 ratio.)
    </p>
    <p class="aspect-ratio-integer">
        This should be green if the viewport aspect-ratio is at least 2. (So, at least twice as wide as it is tall.)
    </p>
    <p class="aspect-ratio-decimal">
        This should be green if the viewport aspect-ratio is less than 0.5. (So, at least twice as tall as it is wide.)
    </p>

    <script>
        let mql = window.matchMedia("(min-width: 800px)");
        function update_match_text(input) {
            if (input.matches) {
                document.getElementById("interactive").innerHTML = "<code>window.matchMedia(\"(min-width: 800px)\")</code> matches!";
            } else {
                document.getElementById("interactive").innerHTML = "<code>window.matchMedia(\"(min-width: 800px)\")</code> doesn't match!";
            }
        }
        mql.addEventListener("change", update_match_text);
        update_match_text(mql);
    </script>
</body>
</html>