postcss / postcss-custom-properties

Use Custom Properties in CSS
https://postcss.github.io/postcss-custom-properties
MIT License
597 stars 77 forks source link

Fallback for CSS variable assigned to a CSS variable #133

Closed mevbg closed 5 years ago

mevbg commented 5 years ago

If I have this code:

:root {
    --col-light: #fff;
    --main-background: var(--col-light);
}

body {
    background-color: var(--main-background);
}

The output will be like so:

:root {
    --col-light: #fff;
    --main-background: #fff; // a fallback value where it's not needed
    --main-background: var(--col-light);
}

body {
    color: var(--main-background);
}

I expect the compiler to pass the first variable's value (#fff) through the second variable to the property and to have an output like this one:

:root {
    --col-light: #fff;
    --main-background: var(--col-light);
}

body {
    color: #fff; // a properly placed fallback value
    color: var(--main-background);
}

Because now the outcome makes the Fallback feature useless.