sass和less的对比

// https://www.sass.hk/guide/
// Sass是基于Ruby的,是在服务器端处理的。
/*!
  @author:xuping,即使是压缩模式的的编译,也会保留这行注释
*/
/* 
    comment:会保留到编译后的文件。
 */ 
// comment,只保留在SASS源文件中,编译后被省略。
// 变量以$开头
$blue : #1875e7;
 div {
    color : $blue;
}
// 如果变量需要镶嵌在字符串之中,就必须需要写在#{}之中。
$side : left;
.rounded {
    border-#{$side}-radius: 5px;
}
//  计算功能
body {
 margin:(14px/2);
 top50px + 100px;
}
// 嵌套、伪类
// p {
//     color: #dddddd;
//     h1 {
//      color: #333;
//     }
// }
// a {
//     &:hover { color: #ffb3ff; }
// }
/*
 * 代码的重用
*/
// class2要继承class1,就要使用@extend命令:
.class1 {
  border1px solid #ddd;
}
.class2 {
    @extend .class1;
  font-size:120%;
}

// Mixin 可以重用的代码块。参数和缺省值。

@mixin left($value10px) {
    floatleft;
    margin-left:10px;
}
div {
    @include left(20px);
}
// 颜色函数
/*
   darken(#cc3, 10%) // #a3a329
  grayscale(#cc3) // #808080
  complement(#cc3) // #33c   
*/
.color{
    color:lighten(#cc310%// #d6d65c
}
// 插入文件
@import "foo.css";

/*
 * IF for while each 自定义函数
*/
p {
    @if 5 < 3 { border2px dotted; }
}
// if/else
@if lightness($color) > 30% {
    background-color#000;
@else {
    background-color#fff;
}
// while
$i:6;
@while $i > 0 {
 .item-#{$i} { width2em * $i; }
}
// for
@for $i from 1 to 10 {
    .border-#{$i} {
      border#{$i}px solid blue;
    }
}
// function
@function double($n) {
    @return $n * 2;
}
#sidebar {
    widthdouble(5px);
}
// https://less.bootcss.com/
// 注释,不会被编译
/*
   这也是less中的注释,但是会被编译
   Less 既可以在客户端上运行 (支持IE 6+, Webkit, Firefox),也可在服务端运行。
*/
@width10px;
@height@width + 10px;

#header {
  width@width;
  height@height;
}
// 计算功能
.color{
    background-color:#112244 + #111// 结果是 #223355
}
// 嵌套
#header {
    colorblack;
    .navigation {
      font-size12px;
    }
    .logo {
      width300px;
    }
  }
 /*
  代码复用
 */ 
 // 继承
 .parentClass{
    color:red;
}
.subClassOne{
    &:extend(.parentClass);
}
.subClassTwo:extend(.parentClass){
    
}
// Mixin
.bordered {
    border-topdotted 1px black;
    border-bottomsolid 2px black;
}

#menu a {
    color#111;
    .bordered();
}
// 颜色函数,内置函数
@base#f04615;
@width0.5;

.class {
  widthpercentage(@width); // returns `50%`
  colorsaturate(@base5%);
  background-colorspin(lighten(@base25%), 8);
}
// 映射
#colors() {
    primary: blue;
    secondary: green;
}
.button {
    color#colors[primary];
    border1px solid #colors[secondary];
}
// 遍历循环
.loop(@iwhen (@i < length(@bgcardList)+1){
    .backgroundcard(extract(@bgcardList@i),extract(@bgcardList@i));
    .loop(@i+1);
}
.loop(1);
 // if 条件
 @dr: if(@my-option = true, {
    button {
      colorwhite;
    }
    a {
      colorblue;
    }
  });
  @dr();

  
pasting
原文地址:https://www.cnblogs.com/yayaxuping/p/11813547.html