zoukankan      html  css  js  c++  java
  • sass初级语法

    github地址:https://github.com/lily1010/sass/tree/master/course01

    用到的sass语法是:

    sass --watch test.scss:test.css --style expanded

    如下图:

    
    

    1 自定义变量

    test.scss内容是:

    $color: black;
    .test1 {
        background-color: $color;
    } 

    编译成test.css内容是:

    .test1 {
      background-color: black;
    }

    2 在字符串内加变量

    test.scss内容是:

    $left: left;
    .test2 {
        border-#{$left}:1px  #000 solid;
    }

    编译成test.css内容是:

    .test2 {
      border-left: 1px  #000 solid;
    }

    3 样式内进行加减乘除(注意除法书写)

    test.scss内容是:

    $para:4;
    .test3 {
        height: 5px+3px;
         (14px/7);
        right: $para*4;
    }

    编译成test.css内容是:

    .test3 {
      height: 8px;
       2px;
      right: 16;
    }

    4 子元素书写

    test.scss内容是:

    .test4 {
        .lala {
            color: pink;
        }
    }

    编译成test.css内容是:

    .test4 .lala {
      color: pink;
    }

    5 继承(SASS允许一个选择器,继承另一个选择器)

    test.scss内容是:

    .class1 {
        border-left: 1px #000 solid;
    }
    .class2 {
        @extend .class1;
        font-size: 15px;
    }

    编译成test.css内容是:

    .class1, .class2 {
      border-left: 1px #000 solid;
    }
    .class2 {
      font-size: 15px;
    }

    6 复用代码块

    test.scss内容是:(无变量)

    @mixin test6 {
        height: 5px;
        left: 20px;
        top: 10px;
    }
    .lili {
        @include test6;
    }

    编译成test.css内容是:(无变量)

    .lili {
      height: 5px;
      left: 20px;
      top: 10px;
    }

    这个方法很好用的是可以设置变量,如下:

    test.scss内容是:(有变量)

    @mixin test62($height) {
        height: $height;
        left: 20px;
        top: 10px;
    }
    .lili2 {
        @include test62(100px);
    }

    编译成test.css内容是:(有变量)

    .lili2 {
      height: 100px;
      left: 20px;
      top: 10px;
    }

    7 函数

    test.scss内容是:

    @function aa($color) {
        @return $color;
    }
    .test7 {
        color: aa(pink);
    }

    编译成test.css内容是:

    /*example 07*/
    .test7 {
      color: pink;
    }

    8 导入外部scss或者css文件

    test.scss内容是:

    @import 'more.scss' 

    more.scss内容是:

    $ 30px;
    .test8 {
         $width;
    }

    编译成test.css内容是:

    .test8 {
       30px;
    }
  • 相关阅读:
    生成器,生成器表达式。
    device busy
    memcached
    ps f
    Eviews9.0---软件安装
    免费提取百度文库 doc 文件
    Matlab---length函数
    Matlab 路径函数
    matlab中disp函数的简单用法
    MATLAB---dir函数
  • 原文地址:https://www.cnblogs.com/lily1010/p/5807651.html
Copyright © 2011-2022 走看看