一、变量

所有变量以$开头

$font_size: 12px;
.container{
font-size: $font_size;
}

如果变量嵌套在字符串中,需要写在#{}中

$side : left;
.rounded {
border-#{$side}: 1px solid #000;
}

二、嵌套

层级嵌套

.container{
display: none;
.header{
width: 100%;
}
}

属性嵌套,注意,border后需要加上冒号:

.container {
border: {
width: 1px;
}
}

可以通过&引用父元素,常用在各种伪类

.link{
&:hover{
color: green;
}
}

三、mixin

简单理解,是可以重用的代码块,通过@include 命令

// mixin
@mixin focus_style {
outline: none;
}
div {
@include focus_style;
}

编译后生成

div {
outline: none; }

还可指定参数、缺省值

// 参数、缺省值
@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; }

四、继承

通过@extend,一个选择器可以继承另一个选择器的样式。例子如下

// 继承
.class1{
float: left;
}
.class2{
@extend .class1;
width: 200px;
}

编译后生成

.class1, .class2 {
float: left; } .class2 {
width: 200px; }

五、运算

直接上例子

.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注释,会保留到编译后的代码中 */

如果重要的注释,压缩编译后还想保留,可在 /* 后面加上 !

/*!
重要注释,压缩编译也不会消失
*/

参考:

http://www.ruanyifeng.com/blog/2012/06/sass.html

最新文章

  1. 新版本MySQL Server 5.7的免安装版本设置
  2. Ninject学习笔记<一>
  3. 再论EM算法的收敛性和K-Means的收敛性
  4. log tree(merge)
  5. android4.4.2 短信广播变更
  6. [iOS基础控件 - 6.11.2] - UINavigationController 多控制器 简单使用
  7. UVA 11928 The Busy Dog
  8. Android学习笔记(1)—Android Studio安装
  9. C++ 11 笔记 (六) : 随机数
  10. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家( 平衡树 )
  11. oracle导入数据
  12. [Angular Directive] Assign a Structual Directive a Dynamic Context in Angular 2
  13. Ajax需要带头信息跨域问题的解决
  14. 030_CORS深究
  15. ?:,reverse,vector的基本小结
  16. ionic2集成sdk后,连接超时的问题
  17. tf-slim-mnist
  18. ==和equal()的区别
  19. sqler sql 转rest api 的docker image
  20. ubuntu系统部署web项目

热门文章

  1. Huawei DHCP 全局配置与接口配置
  2. Innodb存储引擎的缓存命中率计算
  3. 团队作业7——第二次项目冲刺(Beta版本)day3
  4. 【Ansible 文档】配置
  5. xpath获取带注释的text
  6. day4-课堂代码
  7. shiro实战系列(七)之Realm
  8. 如何快速找到某个研究领域的所有SCI期刊
  9. OpenCV——直方图均衡化(用于图像增强)
  10. 复习整理2:juit