Answer the question
In order to leave comments, you need to log in
CSS Variable Inheritance. How to do it right?
The situation is the following. There is a CSS variable A which sets the color. This variable is used for another variable (B), which in turn is used to set the background color. If you change the color of variable A for a nested element, and specify that the background color of the element is equal to variable B, then the background color does not change. How to make it work. Do not ask why such frills - this is a greatly simplified scheme of the working system.
A demonstration of the problem can be viewed here
HTML
<div class="test-block bg-color">
В этом пряугольнике должне быть красный цвет фона.
</div>
:root{
--sf-color: #DBEDFF;
--sf-test: var(--sf-color);
background-color: var(--sf-test);
}
.bg-color{
--sf-color: #FDAEB7;
background-color: var(--sf-test);
}
.test-block{
width: 100%;
height: 50vh;
border: 2px solid #333;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
}
Answer the question
In order to leave comments, you need to log in
.bg-color{
--sf-color: #FDAEB7;
--sf-test: var(--sf-color);
background-color: var(--sf-test);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question