13.3. Sass variable

发布时间 :2024-02-28 23:00:07 UTC      

Variables are used to store some information and can be reused.

Sass variables can store the following information:

  • String

  • Figures

  • Color value

  • Boolean value

  • List

  • Null value

Sass variable use $ symbol:

$variablename: value;

The following example sets four variables: myFont , myColor , myFontSize , and myWidth .

After the variable is declared, we can use it in the code:

13.3.1. Sass code:

$myFont: Helvetica, sans-serif;
$myColor: red;
$myFontSize: 18px;
$myWidth: 680px;
body {
  font-family: $myFont;
  font-size: $myFontSize;
  color: $myColor;
}
#container {
  width: $myWidth;
}

Convert the above code to CSS code, as follows:

13.3.2. Css Code:

body {
  font-family: Helvetica, sans-serif;
  font-size: 18px;
  color: red;
}
#container {
  width: 680px;
}

Sass scope

The scope of a Sass variable can only have an effect at the current level, as follows the h1 style of the green , p tag is for red .

Sass code:

$myColor: red;
h1 {
  $myColor: green;   // Only useful in h1, local scope
  color: $myColor;
}
p {
  color: $myColor;
}

Convert the above code to CSS code, as follows:

Css Code:

h1 {
  color: green;
}
p {
  color: red;
}

13.3.3. !global

That’s for sure Sass , we can use the !global keyword to set the variable is global:

Sass code

$myColor: red;
h1 {
  $myColor: green !global;  // Global scope
  color: $myColor;
}
p {
  color: $myColor;
}

Now the p style of the label becomes green .

Convert the above code to CSS code, as follows:

Css code

h1 {
  color: green;
}
p {
  color: green;
}

Note: all global variables are generally defined in the same file, such as: \_globals.scss and then we use the @include to include the file.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.