When you create a variable, it becomes available for you to use inside the element in which you create it. It also becomes available within any elements nested within it. This effect is known as cascading.
Because of cascading, CSS variables are often defined in the :rootelement.
You can think of the :root
element as a container for your entire HTML document, in the same way that an html
element is a container for the body
element.
By creating your variables in :root
, they will be available throughout the whole web page.
[php]
<style>
:root {
/* add code below */
–myvariable-bottom: gray;
/* add code above */
}
body {
/* var(–myvariable-bottom, fallback value);*/
background:var(–myvariable-bottom, #efccef);
}
.someclass {
top: 15%;
left: 35%;
background: var(–myvariable-bottom, white);
width: 60%;
height: 70%;
border-radius: 70% 70% 60% 60%;
}
</style>
[/php]