css
hello i have a problems when i change the variables of css in the styles.css nothing applied to my website template.
Hi, as you have not given any example, explaining some common mistakes while using CSS variables. 1) Incorrect Declaration CSS variables must begin with --. Without it, the variable won't work. Incorrect: :root { primary-color: #3498db; /* Missing -- before the variable name */ } Correct: :root { --primary-color: #3498db; } 2) Using Variables Outside of var() Variables should always be used within the var() function. Incorrect: .header { background-color: --primary-color; /* Missing var() */ } Correct: .header { background-color: var(--primary-color); } 3) Undefined Variables If a variable is not defined, it will result in an invalid property value. Incorrect: .footer { color: var(--undefined-color); /* --undefined-color is not defined anywhere */ } Correct (with fallback): .footer { color: var(--undefined-color, #000); /* Falls back to #000 */ } 4) Scope Limitations Declaring variables inside a selector limits their scope. Incorrect: .container { --local-color: #ff5733; } .text { color: var(--local-color); /* This won't work as --local-color is not defined globally */ } Correct: :root { --global-color: #ff5733; /* Defined globally */ } .text { color: var(--global-color); } Other than the above, browser caching or incorrect path to CSS file might be the problem. I hope this helps :)
- You must login to reply
- You must login to post answer
Hi, as you have not given any example, explaining some common mistakes while using CSS variables.
1) Incorrect Declaration
CSS variables must begin with –. Without it, the variable won’t work.
Incorrect:
:root {
primary-color: #3498db; /* Missing — before the variable name */
}
Correct:
:root {
–primary-color: #3498db;
}
2) Using Variables Outside of var()
Variables should always be used within the var() function.
Incorrect:
.header {
background-color: –primary-color; /* Missing var() */
}
Correct:
.header {
background-color: var(–primary-color);
}
3) Undefined Variables
If a variable is not defined, it will result in an invalid property value.
Incorrect:
.footer {
color: var(–undefined-color); /* –undefined-color is not defined anywhere */
}
Correct (with fallback):
.footer {
color: var(–undefined-color, #000); /* Falls back to #000 */
}
4) Scope Limitations
Declaring variables inside a selector limits their scope.
Incorrect:
.container {
–local-color: #ff5733;
}
.text {
color: var(–local-color); /* This won’t work as –local-color is not defined globally */
}
Correct:
:root {
–global-color: #ff5733; /* Defined globally */
}
.text {
color: var(–global-color);
}
Other than the above, browser caching or incorrect path to CSS file might be the problem.
I hope this helps 🙂
- Muvi answered 4 weeks ago
- You must login to post comments
Please login first to submit.
Ask Question