支持常规的两种注释方法;
1. //双斜杠的单行注释, eg : //这是一个圆角按钮
2. /**/范围注释, eg:
/*
什么功能;
做什么用的;
*/编码@charset "encoding-name"; , 若需要支持中文注释,在SCSS文件的顶部写上@charset "UTF-8";
$fs:12px;
p{
font-size: $fs;
}$fs:12px !default;
p{
font-size: $fs;
}
$fs:15px;
$fs:12px !default;
p{
font-size: $fs;
}$fs:12px;
p{
font-size: $fs;
}$fs:12px;
p{
$fs : 20px;
font-size: $fs;
}除了个别选择符,基本和CSS一样,就是写法是内嵌格式 - 元素嵌套
#main{
p{ font-size:15px} //css : #main p{};
>a{
span{font-size:10px;}
}
}#main{
border{
top:1px solid #ccc;
left:2px solid #ddd;
}
}& : 父类选择符#main{
p{ font-size:15px} //css : #main p{};
>a{
&:link,
&:visited{}
&:hover{};
&:active{};
}
}% 占位符,减少CSS无用的样式的好方法若是用调用,则占位符变量生效,无则不生效;可以避免@extend class的隐患
%mr5{
margin-right:5px;
}
body{
@extend %mr5;
}宏其实有点类似编程语言的函数,都是以达到复用为目的的 - 不带参数混合宏
@mixin ul-unstyle{
list-style:none;
} $width:50px;
$display:inline-block;
@mixin li-unstyle($width,$display){
list-style:none;
width:$width;
display:$display;
}
ul{
@include li-unstyle($width,$display);
} @mixin li-unstyle($width:5px,$display:block){
list-style:none;
width:$width;
display:$display;
}
li{
@include li-unstyle;
} $width:50px;
$display:inline-block;
@mixin li-unstyle($width,$display){
list-style:none;
width:$width;
display:$display;
}
ul{
@include li-unstyle(500px,block);
}$shadow:0 0 3px rgba(#000,.5);
@mixin sw($shadow...){
text-shadow:$shadow;
}
p{
@include sw($shadow);
}可以设置参数以字符串的形式输出
$test:(margin,border);
@mixin t($t1, $t2){
@each $t3 in $test{
#{$t3}-#{$t1}:$t2;
}
}
.btn{
@include t(right,5px);
}SCSS有以下这么多数据类型数字,字符串,颜色,布尔值,空值,值列表 - 数字: 1、 2、 13、 10px; - 字符串:有引号字符串或无引号字符串,如,”foo”、 ‘bar’、 baz; - 颜色:blue、 #04a3f9、 rgba(255,0,0,0.5); - 布尔型:true、 false; - 空值: null; - 值列表:1.5em 1em 0 2em Helvetica, Arial, sans-serif。[用空格或者逗号分开]
都建议用括号包起来,只要单位相同,都可以做运算;不同单位,少数会报错 - 比如除法,因为CSS有双参数斜杆隔开的写法: 50px/30px , SCSS是无法识别的位除法的,加了括号即可 - 颜色也可以做运算; - 变量也可以做运算;
@mixin tt($b:false){
@if $b{
border-right:5px;
}
@else{
@for $i from 1 through 3 {
.item-#{$i} { width: 2em * $i; }
}
}
}
.b1{
@include tt($b:true);
}
.b2{
@include tt;
}@for $i from 1 through 3 {
.item-#{$i} { width: 2em * $i; }
}$num : 2;
$height: 10px;
@while $num > 0 {
.page-#{height}{
height:$height * $num;
};
$num : $num - 1;
}@each 循环就是去遍历一个列表,然后从列表中取出对应的值
@each 循环指令的形式:@each $var in
$test:top,right,bottom,left;
@mixin btn-extend{
@each $i in $test{
border-#{$i}:5px;
}
}
.btn{
@include btn-extend;
}p:before{
content:unquote("sss");
}
p:before{
content:unquote('"sss"');
}.test {
text: to-upper-case(aaaaa);
text: to-upper-case(aA-aAAA-aaa);
}
.test2{
text: to-lower-case(AAAZDc)
}
/*
.test {
text: AAAAA;
text: AA-AAAA-AAA;
}
.test2 {
text: aaazdc;
}
*/$fs:5.3;
$t:10 99 1 2 3 4 5 6;
.test{
height:percentage($fs);
width:round($fs);
width:ceil($fs);
width:floor($fs);
width:abs($fs);
width:min($t...);
width:max($t...);
border-radius:random();
}length(10px) print 1 ,input length(border 1px solid) print3;nth(10px 20px 30px,2),print 20px; join((blue,red),(#abc #def)) ,print (#0000ff, #ff0000, #aabbcc, #ddeeff);append(10px 20px ,30px) , print (10px 20px 30px);zip(1px 2px 3px,solid dashed dotted,green blue red) , print ((1px "solid" #008000), (2px "dashed" #0000ff), (3px "dotted" #ff0000));index(1px solid red, solid) , print 2;还有一些终端相关的命令,以后有空再更新,比较少用scss终端版本,基本用gulp来编译,也就很少调试寻找这些了..