全部變量以$開頭javascript
$font_size: 12px; .container{ font-size: $font_size; }
若是變量嵌套在字符串中,須要寫在#{}中css
$side : left; .rounded { border-#{$side}: 1px solid #000; }2、嵌套
層級嵌套java
.container{ display: none; .header{ width: 100%; } }
屬性嵌套,注意,border後須要加上冒號:ide
```javascript .container { border: { width: 1px; } }
能夠經過&引用父元素,經常使用在各類僞類函數
.link{ &:hover{ color: green; } }
3、mixin
簡單理解,是能夠重用的代碼塊,經過@include 命令code
// mixin @mixin focus_style { outline: none; } div { @include focus_style; }
編譯後生成繼承
div { outline: none; }
還可指定參數、缺省值ip
// 參數、缺省值 @mixin the_height($h: 200px) { height: $h; } .box_default { @include the_height; } .box_not_default{ @include the_height(100px); }
編譯後生成字符串
.box_default { height: 200px; } .box_not_default { height: 100px; }4、繼承
經過@extend,一個選擇器能夠繼承另外一個選擇器的樣式。例子以下scss
// 繼承 .class1{ float: left; } .class2{ @extend .class1; width: 200px; }
編譯後生成
.class1, .class2 { float: left; } .class2 { width: 200px; }5、運算
直接上例子
.container{ position: relative; height: (200px/2); width: 100px + 200px; left: 50px * 2; top: 50px - 10px; }
編譯後生成
.container { position: relative; height: 100px; width: 300px; left: 100px; top: 40px; }
插入文件
用@import 來插入外部文件
@import "outer.scss";
也可插入普通css文件
@import "outer.css";
自定義函數
經過@function 來自定義函數
@function higher($h){ @return $h * 2; } .container{ height: higher(100px); }
編譯後輸出
.container { height: 200px; }
註釋
兩種風格的註釋
// 單行註釋,編譯後消失
/* 標準的CSS註釋,會保留到編譯後的代碼中 */
若是重要的註釋,壓縮編譯後還想保留,可在 /* 後面加上 !
/*! 重要註釋,壓縮編譯也不會消失 */