I have a varaible:
$font-color: red;
How do I overwrite its value on smaller screens?
This did not work:
$font-color: red;
@media (max-width: 500px){
$font-color: blue;
}
Also, this is in a global variables file. I want that so whenever on a smaller screen the overwriting of the variable will affect everything in every other file.
2
Answers
In SCSS, variables are set at compile time and cannot be changed dynamically during runtime. Therefore, if you want to change the value of a variable based on a media query, you need to structure your code differently.
One way to achieve what you want is to use the variable in a CSS rule inside the media query, rather than trying to redefine the variable itself. Here’s an example:
You might consider using CSS variables, they can be modified at runtime using media queries.
Here’s an example:
For the sake of completeness, using SASS variables dynamically