&: 父選擇器css
$: 聲明變量 $themo_color: #ff0000;
數組
數據類型: 數字、字符串、顏色、布爾值、空值、數組(用空格或逗號做分隔符)、maps (key1: value1, key2: value2)ide
運算類型: 數字運算(+ - * / %) 關係運算(> < >= <=)布爾運算(and or not)函數
函數:color: hsl(saturation: 100%, $lightness: 50%); 可傳參spa
#{}:插值語句,在選擇器或屬性名中使用變量, 例 #{$attr}-color: blue;.net
@import 注意:scss文件包含媒體查詢時僅作css語句引入code
@import "rounded-corners", "text-shadow"; 導入多個文件對象
文件名前添加下劃線時不編譯這些文件,但導入語句中卻不須要添加下劃線。繼承
@media: 媒體查詢rem
.sidebar {
width: 300px;
@media screen and (orientation: landscape) {
width: 500px;
}
}
編譯爲:
.sidebar {
width: 300px;
}
@media screen and (orientation: landscape) {
.sidebar {
width: 500px;
}
}
複製代碼
繼承樣式類: @extend .error;
使用
#context %extreme {
color: blue;
}
.notice {
@extend %extreme;
}
編譯
#context .notice {
color: blue;
}
複製代碼
!特別提醒: 在製做 Sass 樣式庫的時候使用,Sass 可以忽略用不到的樣式。
//定義
@mixin large-text($size,$color: #333){ //參數能夠設置默認值
font: {
family: Arial;
size: $size;
weight: bold;
}
color: $color;
}
//引用
@include large-text(20px, #fba);
@include large-text($size: 20px, $color: #fba); //關鍵詞參數,相似js對象
複製代碼
$grid-width: 40px;
$gutter-width: 10px;
//定義
@function grid-width($n) {
@return $n * $grid-width + ($n - 1) * $gutter-width;
}
//引用
#sidebar { width: grid-width(5); }
複製代碼