天天看點

Sass導入其它Sass檔案

和 LESS 一樣 SASS 檔案中也支援導入其它 SASS 檔案,其實原生的 CSS 也支援通過 ​

​@import​

​​ 導入其它的 CSS 檔案,隻不過不常用,不常用的原因在于原生的 ​

​@import​

​​ 導入其它的 CSS 檔案,隻有執行到 ​

​@import​

​​ 時浏覓器才會去下載下傳對應 CSS 檔案,這導緻請求次數變多,頁面加載起來特别慢,而 LESS 和 SASS 中的 ​

​@import​

​ 是直接将導入的檔案拷貝到目前檔案中生成一份 CSS,是以隻會請求一次,速度更快:

index.scss 内容如下:

@import "center";

div {
  width: 200px;
  height: 200px;
  background: red;
  @include center;
}      

建立一個 center.scss 檔案内容如下:

@mixin center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}      
Sass導入其它Sass檔案