Sass选择器嵌套
.content {}
body .content {}
.content {
body & {}
}
.content {}
.content_cover {}
.content_info_name {}
.content {
&_cover {}
&_info {
&_name
}
}
Sass属性嵌套
.content {
background-color: red;
background-repeat: no-repeat;
background-image: url(/img/icon.png);
background-position: 0 0;
}
.content {
background : {
color: red;
repeat: no-repeat;
image: url(/img/icon.png);
position: 0 0;
}
}
Sass变量
// CSS
.content {
color: red;
border-color: red;
}
//SCSS
$color: red;
.content {
color: $color;
border-color: $color;
}
Sass混合(mixin)
// CSS
.content_1 {
-webkit-border-radius: 5px;
border-radius: 5px;
}
.content_2 {
-webkit-border-radius: 10px;
border-radius: 10px;
}
//SCSS
@mixin radius($radius:5px) { //这是默认值写法
-webkit-border-radius: $radius;
border-radius: $radius;
}
.content_1 {
@include radius; //不传参用默认值
}
.content_2 {
@include radius(10px);
}