JavaScript----less

2018-11-25  本文已影响0人  AuglyXu

less

<link rel="stylesheet/less" href="css/10-less文件中引入其他less文件.less">
<script src="js/less.min.js"></script>

less注释

less中的变量

@color: yellow
div{
 @color: blue
  background-color: @color; //blue
}
p{
  background-color: @color; //yellow
}

less中的运算

margin-left: ( -200px / 2 );

less混合

//.center{
//  position: absolute;
//  left: 50%;
//  top: 50%;
//  transform: translateX(-50%) translateY(-50%);
//}
.center(){
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
.box1{
  width:200px;
  height:200px;
  background: red;
  .center();
}
.box2{
  width: 200px;
  height: 200px;
  background: blue;
  //position: absolute;
  //left: 50%;
  //top: 50%;
  //transform: translateX(-50%) translateY(-50%);
  .center;
}
带参数的混合
.center(){
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);

.init(@width:200px,@height:200px,@color:red){
  width:@width;
  height:,@height;
  background: @color;
}

.box1{
  .init(200px,200px,blue)
  .center();
}
.box2{
  .init(300px,300px,red)
  .center;

less可变参数

.transition(...){
  transition: @arguments;
}
div{
  width: 200px;
  height: 200px;
  background: red;
  //transition: margin-left 2s linear 0s;
  //.transition(margin-left, 2s, linear, 0s);
  .transition(margin-left, 2s);
}

less混合的匹配模式

// 只要任意和匹配模式被执行, 这个混合都会被执行
.triangle(@_ ,@w, @c){
  width: 0;
  height: 0;
  overflow: hidden;
}
.triangle(Down,@w, @c){
  border-width: @w;
  border-style: solid dashed dashed dashed ;
  border-color: @c transparent transparent transparent;
}
.triangle(Up,@w, @c){
  border-width: @w;
  border-style: dashed dashed solid dashed ;
  border-color: transparent transparent @c transparent;
}
.triangle(Left,@w, @c){
  border-width: @w;
  border-style: dashed solid dashed dashed ;
  border-color: transparent @c transparent transparent;
}
.triangle(Right,@w, @c){
  border-width: @w;
  border-style: dashed dashed dashed solid;
  border-color: transparent transparent transparent @c;
}
div{
  //.triangle(Down ,20px, red);
  //.triangle(Up ,20px, red);
  //.triangle(Left ,20px, red);
  .triangle(Right ,40px, red);
}

less中引入其他less文件

@import triangle.less

less中的函数

less中&的使用

如下

div{
  width: 200px;
  height: 200px;
  background: red;
  &:hover{
     background: blue; //当鼠标悬停变成蓝色
  }
}

以上代码相当于

div{
  width: 200px;
  height: 200px;
  background: red;
}
div:hover{
     background: blue; //当鼠标悬停变成蓝色
  }

less中的继承

.center{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
}
.box1:extend(.center){
  width: 300px;
  height: 300px;
  background: red;
}
.box2{
  &:extend(.center);
  width: 100px;
  height: 100px;
  background: blue;
  //.center;
}

以上代码相当于

.center,.box1,.box2 {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
}
.box1 {
    width: 300px;
    height: 300px;
    background: red;
}
.box2 {
    width: 100px;
    height: 100px;
    background: blue;
}
上一篇 下一篇

猜你喜欢

热点阅读