zoukankan      html  css  js  c++  java
  • less知识点总结(二)

    变量:以@开头,由于变量只能定义一次,其本质就是“常量”。

    @nice-blue: #5B83AD;
    @light-blue: @nice-blue + #111;
    
    #header {
      color: @light-blue;
    }

    执行后:

    #header {
      color: #6c94be;
    }

    混合:可以将一个定义好的class A轻松的引入到另一个class B中,从而简单实现class B继承class A中的所有属性。我们还可以带参数地调用,就像使用函数一样。同样也可以使用#ids来做混合

     1 .bordered {
     2   border-top: dotted 1px black;
     3   border-bottom: solid 2px black;
     4 }
     5 #menu a {
     6   color: #111;
     7   .bordered;
     8 }
     9 
    10 .post a {
    11   color: red;
    12   .bordered;
    13 }

    编译如下:

    .bordered {
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }
    #menu a {
      color: #111;
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }
    .post a {
      color: red;
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }

    demo2如下:

    #name {
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }
    #menu a {
      color: #111;
      #name;
    }

    编译后如下:

    #name {
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }
    #menu a {
      color: #111;
      border-top: dotted 1px black;
      border-bottom: solid 2px black;
    }

    运算

    任何数字、颜色或者变量都可以参与运算。下面是一组案例:

    @base: 5%;
    @filler: @base * 2;
    @other: @base + @filler;
    
    color: #888 / 4;
    background-color: @base-color + #111;
    height: 100% / 2 + @filler;

    作用域(scope):

    Scope in Less is very similar to that of programming languages. Variables and mixins are first looked for locally, and if they aren't found, the compiler will look in the parent scope, and so on.(less的作用域和编程的语言的作用域非常类似,变量和混合首先在当前的作用域查找,找不到,编译器就向父级作用域查找)

    @var: red;
    
    #page {
      @var: white;
      #header {
        color: @var; // white
      }
    }

    编译后如下:

    1 #page #header {
    2   color: #ffffff;
    3 }

    导入(Importe)

    和你预期的工作方式一样。你可以导入一个 .less 文件,此文件中的所有变量就可以全部使用了。如果导入的文件是 .less 扩展名,则可以将扩展名省略掉:

    @import "library"; // library.less
    @import "typo.css";

    URLs

    // Variables
    @images: "../img";
    
    // 用法
    body {
      color: #444;
      background: url("@{images}/white-sand.png");
    }

    编译后:

    body {
      color: #444;
      background: url("../img/white-sand.png");
    }

    混合二(Mixin)—— "Mix-in"  properties from existing styles

    You can mix-in class selectors and id selectors, e.g.

    1 .a, #b {
    2   color: red;
    3 }
    4 .mixin-class {
    5   .a();
    6 }
    7 .mixin-id {
    8   #b();
    9 }

    编译后:

    .a,
    #b {
      color: red;
    }
    .mixin-class {
      color: red;
    }
    .mixin-id {
      color: red;
    }

    当使用混合的时候,圆括号可以省略(Notice that when you call the mixin, the parenthesis are optional)

    .a();   //these lines do the same thing
    .a;

    不输出混合(not outputting the mixin)

        如果创建了混合,但是不想输出它,就在混合后面加一个圆括号。

    .my-mixin {
      color: black;
    }
    .my-other-mixin() {
      background: white;
    }
    .class {
      .my-mixin;
      .my-other-mixin;
    }
    

      编译后:

    .my-mixin {
    color: black;
    }
    .class {
    color: black;
    background: white;
    }

  • 相关阅读:
    ASP.NET MVC WebAPI 上传图片实例
    PowerDesigner设计权限控制数据模型
    ASP.NET中使用WebService异步加载数据显示到页面
    C#+Dotnetbar海益ERP数据管理系统
    centos 6.X minimal 系列最小化安装完成后,安装mono和jexus过程小记录
    MVC3/4伪静态 jexus mvc伪静态
    petapoco 使用 MiniProfiler Glimpse监控
    尝试整理出自己的开发框架1
    初尝Brnshop移植到Linux Mono Jexus环境运行
    (转)Android开发出来的APP在手机的安装路径是?
  • 原文地址:https://www.cnblogs.com/xuzhudong/p/7256025.html
Copyright © 2011-2022 走看看