1.自定义变量css
$color:pink; .test1{ background-color:$color; }
经过编译工具编译出来后app
.test1{ background-color:pink; }
注:时间缘由我在这里只写scss了,就不写编译后的结果,一来方便你们本身去尝试编译,二来增长你们对scss的理解:编译工具kaola很好的一个编译工具,你们能够百度如何使用,再这里就不作过多介绍了。
***
2.插入一个变量koa
$right:right; .test2{ border-#{$right}:1px solid #000; }
3.子元素书写函数
.text3{ .text33{ border:1px solid; } }
4.样式的加减乘除工具
$paramer:3; .text4{ height:(1px+3px); width: (96px/6); right: $paramer*4; }
5.继承url
.class5{ border:1px solid red; } .class5E{ @extend .class5; font-size:20px; }
6.代码块的复用code
@mixin text6 { height:50px; left:20px; } .text6M{ @include text6 } //这里的mixin就是定义一个能够复用的代码段,固然咱们也能够给它传递一个参数,就像这样同样: @mixin text66($height){ height:$heigth; left:20px; } .text6N{ @include text66(100px); }
7.if语法,经过对if的判断来决定使用那一套样式继承
.text7{ @if 1 +2 == 3 { border:1px solid ; } @if 5 < 3 { border:2px dsahed red; } } 固然,咱们都知道if通常是要和else配合的,因此咱们也能够这样写 .test77{ @if lightness($color) > 30%{ background-color:#fff; }@else{ background:#0ff; } } 这里的lightness是一个scss颜色函数,$color指向以前定义的值。
8.循环语法,包括最多见的三种循环方法,for,while,each开发
//for 循环 @for $i from 1 to 5 { .item-#{$i} { border:#{$i}px solid; } } //while 循环 $m:8; @while $m > 0 { .items-#{$m} { width:2em*$m; } $m:$m - 2 ; } //这里能够对$m进行运算 让它每次都减去2 //each 语法 @each $img in q,w,e,r { .#{$img} { background-image:url('#{$img}.png') } }
9.函数语法get
@function double ($number){ @return $number*2; } .text9{ font-size:double(20px); }
10.import导入语法
@import 'other.scss' 这样就在你如今的scss中导入了other.scss编写的scss