Less基本使用

Less安装

npm install -g less

定义变量

@width: 10px
.header{
   width: @width
}

mixins

全局带命名空间和访问符
.bordered { border-top: dotted 1px black; border-bottom: solid 2px black; } .bgcpink{ background-color: pink; } .box{ width: 100px; height: 100px; margin: 0 auto; .bgcpink; .bordered }#bundle() { .button { display: block; border: 1px solid black; background-color: grey; &:hover { background-color: white; } } .tab { ... } .citation { ... } } #header a { color: orange; #bundle.button(); }

嵌套& 表示当前选择器的父级

.clearfix {
  display: block;
  zoom: 1;
​
  &:after {
    content: " ";
    display: block;
    font-size: 0;
    height: 0;
    clear: both;
    visibility: hidden;
  }
}

运算[calc() 特例]

@incompatible-units: 2 + 5px - 3cm; // 结果是 4px
​
@base: 5%;
@filler: @base * 2; // 结果是 10%
@other: @base + @filler; // 结果是 15%

转义

@min768: (min-width: 768px);
.element {
  @media @min768 {
    font-size: 1.2rem;
  }
}

映射,类似带下标的数组取值

#colors() {
  primary: blue;
  secondary: green;
}
​
.button {
  color: #colors[primary];
  border: 1px solid #colors[secondary];
}

作用域

  1. 首先在本地查找变量和混合(mixins),如果找不到,则从“父”级作用域继承

  2. 混合(mixin)和变量的定义不必在引用之前事先定义

  3. @var: red;
    #page {
      #header {
        color: @var; // white
      }
      @var: white;
    }导入

导入

@import "library"; // library.less
@import "typo.css";
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值