|
18 | 18 | } |
19 | 19 | ``` |
20 | 20 |
|
| 21 | +## `true` and `false` |
| 22 | + |
| 23 | +With `@custom-media` you can use the constants `true` and `false`. |
| 24 | +These are especially handy when debugging. |
| 25 | + |
| 26 | +If you are unsure how your page is affected when a certain media query matches or not you can use these, to quickly toggle the results. |
| 27 | +This plugin downgrades these queries to something that works in all browsers. |
| 28 | + |
| 29 | +Quickly check the result as if the query matches: |
| 30 | + |
| 31 | +```pcss |
| 32 | +@custom-media --small-viewport true; |
| 33 | +
|
| 34 | +@media (--small-viewport) { |
| 35 | + /* styles for small viewport */ |
| 36 | +} |
| 37 | +
|
| 38 | +/* becomes */ |
| 39 | +
|
| 40 | +@media (max-color:2147477350) { |
| 41 | + /* styles for small viewport */ |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Quickly check the result as if the query does not match: |
| 46 | + |
| 47 | +```pcss |
| 48 | +@custom-media --small-viewport false; |
| 49 | +
|
| 50 | +@media (--small-viewport) { |
| 51 | + /* styles for small viewport */ |
| 52 | +} |
| 53 | +
|
| 54 | +/* becomes */ |
| 55 | +
|
| 56 | +@media (color:2147477350) { |
| 57 | + /* styles for small viewport */ |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## logical evaluation of complex media queries |
| 62 | + |
| 63 | +It is impossible to accurately and correctly resolve complex `@custom-media` queries |
| 64 | +as these depend on the browser the queries will eventually run in. |
| 65 | + |
| 66 | +_Some of these queries will have only one possible outcome but we have to account for all possible queries in this plugin._ |
| 67 | + |
| 68 | +⚠️ When handling complex media queries you will see that your CSS is doubled for each level of complexity.<br> |
| 69 | +GZIP works great to de-dupe this but having a lot of complex media queries will have a performance impact. |
| 70 | + |
| 71 | +An example of a very complex (and artificial) use-case : |
| 72 | + |
| 73 | +```pcss |
| 74 | +
|
| 75 | +@custom-media --a-complex-query tty and (min-width: 300px); |
| 76 | +
|
| 77 | +@media not screen and ((not (--a-complex-query)) or (color)) { |
| 78 | + /* Your CSS */ |
| 79 | +} |
| 80 | +
|
| 81 | +/* becomes */ |
| 82 | +
|
| 83 | +
|
| 84 | +@media tty and (min-width: 300px) { |
| 85 | +@media not screen and ((not (max-color:2147477350)) or (color)) { |
| 86 | + /* Your CSS */ |
| 87 | +} |
| 88 | +} |
| 89 | +@media not tty and (min-width: 300px) { |
| 90 | +@media not screen and ((not (color:2147477350)) or (color)) { |
| 91 | + /* Your CSS */ |
| 92 | +} |
| 93 | +} |
| 94 | +``` |
| 95 | + |
21 | 96 | ## Usage |
22 | 97 |
|
23 | 98 | Add [PostCSS Custom Media] to your project: |
|
0 commit comments