Inspired by a recent conversation with
@argyleink about using custom properties as a full set of well, properties, I've been experimenting a bit with them for theming purposes.
Instead of having to redefine selectors and nested elements, this can make life a lot easier.
ALT /* define the colors */ :root {
--color-brand: hsl(212 98% 37%);
--color-white: hsl(0 0% 96%);
--color-black: hsl(216 40% 20%);
}
/* set the defaults */
body {
--body: var(--color-white);
--heading: var(--color-white);
--bg: var(--color-black);
--button-text: var(--color-white);
--button-bg: var(--color-brand);
--button-text-hover: var(--color-white);
--button-bg-hover: var(--color-black);
color: var(--body);
background: var(--bg);
}
h1, h2, h3, h4, h5, h6 {
color: var(--heading);
}
.button {
color: var(--button-text);
background: var(--button-bg);
}
.button:hover, .button:focus {
color: var(--button-text-hover);
background: var(--button-bg-hover);
}
ALT /* create themes */ class*="theme-"] {
background: var(--bg);
color: var(--body);
}
.theme-inverted {
--bg: var(--color-white);
--body: var(--color-black);
--heading: var(--color-brand);
}
.theme-brand {
--bg: var(--color-brand);
--body: var(--color-white);
--heading: var(--color-white);
--button-text: var(--color-brand);
--button-bg: var(--color-white);
}
.theme-headache {
--bg: linear-gradient(yellow, blue);
--body: red;
--heading: purple;
--button-bg: orange;
--button-text: black;
--button-bg-hover: green;
--button-text-hover: red;
}