Forgot Password

CLEMENT FLEIG

css

September 11, 2024 09:24 AM

hello i have a problems when i change the variables of css in the styles.css nothing applied to my website template.

Muvi

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 :)

September 12, 2024 05:17 AM
  • You must to post answer
0
0

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 to post comments
Showing 1 result
Your Answer

Please first to submit.