zoukankan      html  css  js  c++  java
  • Sass、Less 和 Stylus区别

    1.基本语法

     /*less*/
      h1{
          color:red;
        }
    
    /*sass*/
    a
    color:red
    
    /* stylus */
    h1 {
      color: #0982C1;
    }
    
    h1
      color: #0982C1;
    
    h1
      color #0982C1
    

    2.变量

    Less css中变量都是用@开头的,sass变量必须是以$开头的
    stylus对变量是没有任何设定的,可以是以$开头,或者任何的字符,而且与变量之间可以用冒号,空格隔开,
    但是在stylus中不能用@开头

    @maincolor : #092873;
    @siteWidth : 1024px;
    @borderStyle : dotted;
    body {
      color: @maincolor;
      border: 1px @borderStyle @mainColor;
      max- @siteWidth;
    }
    

    3.嵌套

    div {
      font-size:16px;
      p{
          font-size:14px;
          span{
                font-size:14px;
              }
       }
    }
    

    4.运算符

    body {
      margin: (14px/2);
      top: 50px + 100px;
      right: 80 * 10%;
    }
    

    5.继承

    less

    .message {
      border: 1px solid #ccc;
      padding: 10px;
      color: #333;
    }
    .success {
      .message;
      border-color: green;
    }
    .error {
      .message;
      border-color: red;
    }
    .warning {
      .message;
      border-color: yellow;
    }
    

    sass

    .message {
      border: 1px solid #ccc;
      padding: 10px;
      color: #333;
    }
    .success {
      @extend .message;
      border-color: green;
    }
    .error {
      @extend .message;
      border-color: red;
    }
    .warning {
      @extend .message;
      border-color: yellow;
    }
    

    6.混入

    less

    .error(@borderWidth: 2px) {
      border: @borderWidth solid #F00;
      color: #F00;
    }
    .generic-error {
      padding: 20px;
      margin: 4px;
      .error(); //这里调用默认 border: 2px solid #F00;
    }
    .login-error {
      left: 12px;
      position: absolute;
      top: 20px;
      .error(5px); //这里调用 border:5px solid #F00;
    }
    

    sass

    @mixin error($borderWidth: 2px) {
      border: $borderWidth solid #F00;
      color: #F00;
    }
    .generic-error {
      padding: 20px;
      margin: 4px;
      @ include error(); //这里调用默认 border: 2px solid #F00;
    }
    .login-error {
      left: 12px;
      position: absolute;
      top: 20px;
      @ include error(5px); //这里调用 border:5px solid #F00;
    }
    

    stylus

    error(borderWidth= 2px) {
      border: borderWidth solid #F00;
      color: #F00;
    }
    .generic-error {
      padding: 20px;
      margin: 4px;
      error(); 
    }
    .login-error {
      left: 12px;
      position: absolute;
      top: 20px;
      error(5px); 
    }
    

    7.sass高级语法

    条件语句

    $lte7: true;
    $type: monster;
    .ib{
        display:inline-block;
        @if $lte7 {
            *display:inline;
            *zoom:1;
        }
    }
    p {
      @if $type == ocean {
        color: blue;
      } @else if $type == matador {
        color: red;
      } @else if $type == monster {
        color: green;
      } @else {
        color: black;
      }
    }
    

    循环语句
    1.@for $var from through
    2.@for $var from to
    其中$var表示变量,start表示起始值,end表示结束值,这两个的区别是关键字through表示包括end这个数,而to则不包括end这个数。

    @for $i from 1 to 10 {
      .border-#{$i} {
        border: #{$i}px solid blue;
      }
    }
    
    $i: 6;
    @while $i > 0 {
      .item-#{$i} {  2em * $i; }
      $i: $i - 2;
    }
    
    $animal-list: puma, sea-slug, egret, salamander;
    @each $animal in $animal-list {
      .#{$animal}-icon {
        background-image: url('/images/#{$animal}.png');
      }
    }
    
  • 相关阅读:
    Linux下取代top的进程管理工具 htop
    Linux学习初步
    【程序员的吐槽】八一八那些让你感觉蠢哭了的BUG
    【学习随手记】POSIX消息队列执行报Permission denied的问题。
    【学习总结】环境高级编程源码配置
    【学习总结】UNIX网络编程使用源码配置
    【工作心得】有关主键索引
    【转】More Effective C++ (虚拟构造函数)
    【转】C++ 类中特殊的成员变量(常变量、引用、静态)的初始化方法
    【学习心得】python学习心得
  • 原文地址:https://www.cnblogs.com/-swz/p/14263226.html
Copyright © 2011-2022 走看看