13.7. Sass @ extend and inheritance

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

@extend instruction tells Sass that the style of one selector is inherited from another selector.

If one style is almost the same as another, with only a few differences, usethe @extend seems very useful.

In the following Sass example, we created a basic button style .button-basic , then we define two button styles .button-report and .button-submit . They all inherited .button-basic main difference between them is the background color and font color, and all other styles are the same

13.7.1. Sass Code:

.button-basic  {
  border: none;
  padding: 15px 30px;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
}
.button-report  {
  @extend .button-basic;
  background-color: red;
}
.button-submit  {
  @extend .button-basic;
  background-color: green;
  color: white;
}

Convert the above code to CSS code, as follows:

13.7.2. Css Code:

.button-basic, .button-report, .button-submit {
  border: none;
  padding: 15px 30px;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
}
.button-report  {
  background-color: red;
}
.button-submit  {
  background-color: green;
  color: white;
}

Use @extend after that, we do not need to specify multiple classes in the HTML button label class="button-basic button-report" , you just need to set the class="button-report" , the class would be fine.

@extend reflects the reuse of the code well.

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.