CSS setting global variables and local variables

Source: Internet
Author: User
When we use less or sass, we often use local variables and global variables, but we can also define global variables and local variables to simplify our development efficiency when we use CSS, which is very simple and practical.
1. Setting Global variables
Just declare the line in the CSS file referenced by our root, with the following code:
: rout{
--cssname:value
}
This declares a variable named Cssname, the value of which can be called within the scope of the entire Web page, and is called as follows:
. css{
Color:var (--cssname);
}
This completes the call,
2. Setting Local Variables
In fact, the way to set local variables and global variables is roughly the same, the following:
If we need to declare a local variable inside a container with ID box, so that it can be called within the entire box container, we can do the following:
#box {
--cssname:value;
}
This allows us to declare a local variable named Cssname, which is valued value, which is scoped to any child element of the #box container and is called as follows:
#box. child{
Color:var (--cssname)
}
This completes the call that cannot be invoked outside the scope of the action!
is not very simple ah! We can test the actual code, in the specific development is still very useful oh!

CSS setting global variables and local variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.