全部变量以$开头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注释,会保留到编译后的代码中 */
若是重要的注释,压缩编译后还想保留,可在 /* 后面加上 !
/*! 重要注释,压缩编译也不会消失 */