Home > Enterprise >  CSS Variables not work with custom property fallback values
CSS Variables not work with custom property fallback values

Time:12-29

I am declaring a custom property in :root like below, but my color not work for me. What I am wrong?

:root {
    --color-primary: var(--color-primary, #ffc107);
}
body {
    background-color: var(--color-primary); // background color not work
}

CodePudding user response:

you need to declare the variable in :root like this:

:root {
    --color-primary: #ffc107;
}

CodePudding user response:

Declaring css variables should be like this:

:root {
    --color-primary: #ffc107;
}
body {
    background-color: var(--color-primary);
}

CodePudding user response:

Use like as

:root {--color-primary: #ffc107;} body {background-color: var(--color-primary);}

  • Related