reusing css color attributes

johnbabu021

john

Posted on January 16, 2022

reusing css color attributes
:root{
--primary-color:red;
--secondary-color:blue;

}
Enter fullscreen mode Exit fullscreen mode

root element match the top most element in a web document(tree structure) so when creating variables in root it can be accessed anywhere inside the dom(Document Object Model)
--primary-color,--secondary-color are variablels.We can reuse this elements by the following code

div{
color:var(--primary-color);
background-color:var(--secondary-color);
}
Enter fullscreen mode Exit fullscreen mode

this selects --primary-color to all elements with a div parent and background-color to --secondary-color

πŸ’– πŸ’ͺ πŸ™… 🚩
johnbabu021
john

Posted on January 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

reusing css color attributes
css reusing css color attributes

January 16, 2022

Position: Relatively Confused
css Position: Relatively Confused

January 16, 2021

Explore CSS Units with Theo
css Explore CSS Units with Theo

September 11, 2020