less学习

@width:300px;
@color:#222;
@bgColor:skyblue;
@mySelector:#app;
@bd:border-style;
@mySelector1:input;
@Rules:{
  height: 100px;
  background-color: #333;
}
@import './main.less';
//变量
#wrap{
  color:@color;
  background-color: @bgColor;
}

//选择器
@{mySelector}{
  @{bd}:1px solid #333;
}

//嵌套
//& :代表的上一层选择器的名字,此例便是header
#header{
  .title{
    color: #333;
  }
  &_content{
    background-color: aqua;
  }
  &:after{
    font-family: "Adobe Arabic";
  }
}

//媒体查询
//唯一的缺点就是 每一个元素都会编译出自己 @media 声明,并不会合并。
#main{
  @media screen{
    @media(max-width:768px){
      width:100px
    }
  }
}

//定义自己的私有样式
#main{
  &.show{
    display: block;
  }
}
.show{
  display: none;
}

//无参数方法
//`.` 与 `#` 皆可作为 方法前缀。
.card { // 等价于 .card()
  background: #f6f6f6;
  -webkit-box-shadow: 0 1px 2px rgba(151, 151, 151, .58);
  box-shadow: 0 1px 2px rgba(151, 151, 151, .58);
}
#app{
  .card;
}

//有参数
.border(@a:10px,@b:50px,@c:30px,@color:#000){
  border:solid 1px @color;
  box-shadow: @arguments;//指代的是 全部参数
}
#main{
  .border(0px,5px,30px,red);//必须带着单位
}
#wrap{
  .border(0px);
}
#content{
  .border;//等价于 .border()
}

#card(){
  background-color: red;
  .d(@w:300px){
    width: @w;
    #a(@h:300px){
      height: @h;
      width:@w;
    }
  }
}

#wrap{
  #card;
  .d();
  #a(100px);
}
#main{
  #card .d()
}
#con{
  //不得单独使用命名空间的方法
  //.d() 如果前面没有引入命名空间 #card ,将会报错

  #card; // 等价于 #card();
  .d(20px); //必须先引入 #card
}

//js to css
@content:~'`"aaa".toUpperCase()`';
#randomColor{
  @randomColor: ~"rgb(`Math.round(Math.random() * 256)`,`Math.round(Math.random() * 256)`,`Math.round(Math.random() * 256)`)";
}
#wrap{
  width: ~"Math.round(Math.random() * 100) px";
  &:after{
    content:@content;
  }
  height: ~"`window.innerHeight` px";
  alert:~"`alert(1)`";
  #randomColor();
  background-color: @randomColor;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值