You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/theming/advanced.md
+51Lines changed: 51 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -238,3 +238,54 @@ body {
238
238
color: rgba(var(--ion-text-color-rgb), 0.25);
239
239
}
240
240
```
241
+
242
+
243
+
### Variables in Media Queries
244
+
245
+
CSS variables in [media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries) are not currently supported, but there are open drafts to add [custom media queries](https://drafts.csswg.org/mediaqueries-5/#custom-mq) and [custom environment variables](https://drafts.csswg.org/css-env-1/) that would solve this problem! However, with the current state of support, the following will **not** work:
246
+
247
+
```css
248
+
:root {
249
+
--breakpoint: 600px;
250
+
}
251
+
252
+
@media (min-width: var(--breakpoint)) {
253
+
/* Doesn't work :( */
254
+
}
255
+
```
256
+
257
+
258
+
### Modifying CSS Color Variables
259
+
260
+
While it is possible to easily alter a color in Sass using its built-in functions, it is currently not as easy to modify colors set in CSS Variables. This can be accomplished in CSS by splitting the [RGB](https://developer.mozilla.org/en-US/docs/Glossary/RGB) or [HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) channels and modifying each value, but it is complex and has missing functionality.
261
+
262
+
What exactly does this mean? Basically, using a CSS preprocessor, such as Sass, allows us to use functions to manipulate a single color. For example, we can create the following colors in Sass:
263
+
264
+
```scss
265
+
// Background color, shade, and tint
266
+
$background: #3880ff;
267
+
$background-shade: mix(#000, $background, 12%);
268
+
$background-tint: mix(#fff, $background, 10%);
269
+
270
+
// Text color, darker and lighter
271
+
$text: #444;
272
+
$text-darker: darken($text, 15);
273
+
$text-lighter: lighten($text, 15);
274
+
```
275
+
276
+
After running through the Sass compiler, the colors will have the following values:
However, because CSS variables can be set at runtime and are more dynamic, it is not currently possible to manipulate them using a simple function.
288
+
289
+
This is normally not a problem, but when an application needs to have dynamic theming it presents issues. In Ionic, this is the reason that there are [variations to each color](#layered-colors), and it is also why [stepped colors](#stepped-colors) are necessary for theming.
290
+
291
+
There are drafts and issues discussing [color modification proposals](https://github.com/w3c/csswg-drafts/issues/3187) that would make this possible.
0 commit comments