vscode插件

  1. Easy Compile
  2. ctrl+s //执行编译

1 变量

  1. $txtColor:"#ff2d51";
  2. div{
  3. color:$txtColor;
  4. }

2 嵌套

  1. div{
  2. color:red;
  3. p{
  4. width:100px;
  5. height: 100px;
  6. }
  7. }

3 @mixin(函数)

  1. @mixin wh {
  2. width:100px;
  3. height: 100px;
  4. }
  5. .one{
  6. @include wh;
  7. }

3-1 定义一个带默认参数的@mixin函数

  1. /* 宏函数 */
  2. @mixin wh($w:100px,$h:100px){
  3. width:$w;
  4. height: $h;
  5. }
  6. .one{
  7. @include wh;
  8. }
  9. .two{
  10. @include wh(200px,300px);
  11. }

4@ for

  1. @for $i from 1 through 12 {
  2. .col-#{$i}{
  3. width:$i/12*100%
  4. }
  5. }

5 @if-@else

  1. @mixin v-h($val:true) {
  2. @if $val {
  3. display: block;
  4. }@else{
  5. display: none;
  6. }
  7. }
  8. .v{
  9. @include v-h;
  10. }
  11. .h{
  12. @include v-h(false)
  13. }

6 @extend可以获取另一个class

  1. .three{
  2. @extend .two;
  3. background-color: red;
  4. }

7 map的数据结构,类型

  1. $colors:(
  2. success:#398439,
  3. warning:#ec971f,
  4. danger:#c9302c
  5. );
  6. .btn-danger{
  7. background-color: map-get($map: $colors, $key:danger );
  8. }

8 @function 定义了一个颜色函数

  1. $colors:(
  2. success:#398439,
  3. warning:#ec971f,
  4. danger:#c9302c
  5. );
  6. @function color($key){
  7. @return map-get($map:$colors , $key: $key)
  8. };
  9. .btn-danger{
  10. background-color: color(danger);
  11. }
  12. .btn-success{
  13. background-color: color(success);
  14. }