Get the App
SLTechnology News&Howtos  ›  Development  › 

Whether variables can be defined in css

Shulou Source: shulou.com Published: 2022-05-31 19:05:45 09月15日 Update

This article introduces the relevant knowledge of "whether variables can be defined in css". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Variables can be defined in css. The syntax of the variable definition is "--variable name", and the variable name defined in css is case-sensitive; the var () function can be used to read the variable with the syntax "var (--variable name)", and the second parameter of the function can be used to represent the default value of the variable, which will be used if the variable does not exist.

The operating environment of this tutorial: windows10 system, CSS3&&HTML5 version, Dell G3 computer.

Can variables be defined in css?

Variables can be used in css.

When you declare a css variable, the variable name is preceded by two hyphens (- -). Variable names are case-sensitive,-- header-color and-- Header-Color are two different variables.

The var () function is used to read variables.

The var () function can also take the second argument, which represents the default value of the variable. If the variable does not exist, this default value is used.

The second parameter does not handle internal commas or spaces and is treated as part of the parameter.

Examples of variables used by css:

: root {--base: yellow;-- spacing: 10px;-- blur: 10px;}

The above code defines three variables: root makes it accessible to everyone

Img {filter: blur (var (--blur)); padding: var (--spacing); background: var (--base);}

The above uses the previously defined variable as the attribute value.

That's all for the content of "whether variables can be defined in css". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Variables functions parameters names but not content size more knowledge syntax different practical successful next two code dilemma actual attribute situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Linux Huawei Shulou Information