1
I’m developing a React-based web app that uses Material Components (which in turn uses Sass) and requires the color of the browser bar (defined via html meta, as shown in the following code) to be obtained from the application style (defined in the file _vars.scss
as $c-primary-light: #303E2F;
).
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta name="theme-color" content="var($c-primary-light)"/>
</head>
</html>
Manually setting the color in HTML is not a viable option as the application is of the multi tenant type, where each domain has different colors.
In my approaches (previous code), I tried to get the color from the CSS variable directly in HTML, however I believe that this is not possible.
What are the possible approaches to solving this problem?
Dude, I don’t know if your logic is correct... I don’t know about React, but since you want to take a Sass Variable in HTML, play for Sass, compile the CSS and then deliver the rendered page... This is a little confusing to understand... Even is at the head of the page you would have to compile the Sass with the new color and return the CSS before the page finishes the Paint....
– hugocsl
Basically my problem is to define the
theme-color
according to a style selected in Runtime - and my preference is to "search" this color in the variables of Sass. If that is not possible, I would like suggestions to implement this using other means.– Mathias Berwig
What I’ve seen most recently is the use of CSS Variables with colors, just for the simple fact that it’s already CSS and doesn’t need to compile, and so override is easier... If you want I can put an answer on the subject, I just don’t know if it will be 100% applicable in your case. Maybe this https://answall.com/questions/298995/o-que-significa-o-specified-no-root-do-css-do-bootstrap/298998#298998 and this can give you a light https://answall.com/questions/330390/existe-alguma-forma-de-usar-um-custom-attributomo-valor-de-uma-property
– hugocsl
The links help, yes. I believe that we will need to create a script to solve the value of the CSS variable and then update Theme-color, all via javascript. I still don’t know exactly how to do this. With regard to the answer, I would be happy to mark it as a solution as long as it is the most relevant contribution to solving the problem.
– Mathias Berwig