Chuyển đến nội dung chính

Variable in CSS

     We can use variables in css. CSS Variables are entities defined by authors, or users, of Web pages to contain specific values throughout a document. They are set using custom properties and are accessed using a specific functional notation var().

syntax

   :root

   {

     --variable_name_1:value_1;

     --variable_name_2:value_2;

     ....

     ....

     ....

     --variable_name_n:value_n;

   }

Example

   :root

   {

     --clr:red;

     --mrgn:50px;    

   }



   div

   {

     background:var(--clr);

     margin-top:var(--mrgn);

   }

Problems to solve
     When building large sites, authors often face a maintainability challenge. In such websites, the size of the CSS is quite large and a lot of information may be repeated in multiple places. For example, maintaining a coherent color scheme throughout a document implies reusing a few color values at numerous positions in the CSS files. Altering the scheme, whether tweaking a single color or completely rewriting it, therefore becomes a complex task requiring precision, as a single find and replace often isn't enough.

     The situation gets worse with CSS frameworks, where changing colors requires editing the framework itself. Preprocessors like LESS or Sass are quite helpful in these situations, but may increase the complexity of the creation system, by adding an extra processing step. CSS variables help by employing some of the low-hanging benefits of a preprocessor, without the compilation overhead.

     A second advantage of these variables is that the name itself contains semantic information. CSS files become easier to read and understand: main-text-color is easier to understand than the reuse of #00ff00 throughout the text, especially if this same color is also used in another context.

How CSS Variables can help
     In imperative programming languages, like Java, C++, or even JavaScript, the state can be tracked through the notion of variables. Variables are symbolic names associated with a given value that can vary with the time.

     In a declarative language like CSS, time-changing values are not common, and the concept of variables is also uncommon.

     Nevertheless, CSS introduces the notion of cascading variables in order to help solve the maintainability challenge. This allows for symbolically refering to a value throughout the CSS tree.

What are CSS VariableS
     CSS Variables currently have two forms:

     Variables, which are an association between an identifier and a value that can be used in place of any regular values, using the var() functional notation: var(--example-variable) returns the value of the --example-variable value.
     Custom properties, which are special properties of the form --* where * represents the variable name. These are used to define the value of a given variable: --example-variable: 20px; is a CSS declaration, using the custom --* property to set the value of the CSS variable --example-variable to 20px.


Example Program:- (Editor)


Editor is Loading...

Advertisement

Nhận xét

Popular Posts

ARTCUT 2009 Software USB Driver Free Full Download

Download ARTCUT 2009 Software USB Driver Full Free latest version offline setup for Microsoft Windows 7, 8,  10, XP, Vista. ARTCUT 2009 Software USB Driver is one of the best especially designer inside the agency of cutting plotter machine for operating. ARTCUT 2009 Software USB Driver Overview Artcut 2009 is the 3D realistic programming worked for 5-pivot laser cutting on Without it, with a well-ordered direction through the whole programming procedure. ArtCut programming self-sufficiently amends the courses of the hub in order to avoid crashes with the piece or different components of the machine.  Artcut 2009 Software PC programming is extraordinarily structured inside the organization of plotter cutting for working. You can undoubtedly make, do shrewd trimmings of plastic cutting. It can likewise e create legitimate plotter cuttings. You can have the chance of extra set up for the essential period of work. Stage pay, corner changes, and obtaining methods may...

strict mode in var javascript

        The "use strict" directive is introduce from javascript 1.8.5. This can't able to call statement, but this is a literal expression. This tell the code should be execute in "strict mode". Supported browser:      strict mode is only support from  the following version >IE 9 >Firefox 3 >Chrome 12 >Opera 11 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Counter Terrorist 2 Full APK Free Download

(Counter Terrorist 2) which combines our fans' and our team's great ideas. now is available for download. ☑You can turn "Auto Shoot" ON/OFF in battle. ☑You can modify "Aim Sensitivity" in pause button. ☑More weapons, in 2.0 we have 20 weapons, some are really the "monsters":) ☑More levels, in 2.0 we added 2 more levels which contain gorgeous environment. ☑More smart enemies, in 2.0 we will face much smarter enemies, you'd better not despise them. ☑Harder level means more rewards. Game control: ☑Left 1/3 screen is for moving,right 2/3 screen is for aiming. ☑When you aim the target,your weapon will fire automatially,giving you a much easier FPS game control. ☑You can prepare your bullets before battling,or auto buy bullet in the battle. ☑You can tweak your control sensivity in your pause menu,fit all the android devices here. ☑Auto buying bullets in the battle,save your precious time ☑Aim the head,give your enemy the critical strike! ☑Enemies...