less学习笔记


注释

以“//”的注释不会被编译到css中,以“/**/”会被编译到css中

/*
注释会出现在css文件中
*/

#wrap {
  // 不会出现在css中
  width: 100px;
  height: 100px;
}
/*
注释会出现在css文件中
*/
#wrap {
  width: 100px;
  height: 100px;
}

变量

@变量名:值

@color:yellow

作为选择器

#@{select}

作为url

URL:@{url}

延时加载:如下例使用时会等变量值改变完了在调用

@var:1;
.b{
	@var:2;
	three:@var;//3
	@var:3;
}

嵌套规则

基本嵌套

#div{
	width: 200px;
	.span{
	
	}
}

&的使用,&符号代表当前的父级

#div{
    width: 80px;
    height: 80px;
    // 给div添加hover
    &:hover{
        width: 100px;
    }
}

混合

普通混合

缺点:会编译到css中,使css体积变大

.juzhong{
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
	margin: auto;
}
#wrap{
	.juzhong;
}

等价于

#wrap{
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
	margin: aut
}

带默认值混合

less

.juzhong(@c:10px, @h){
	position: absolute;
	left: 0;
	right: 0;
	top: @h;
	bottom: @c;
	margin: auto;
}
#wrap1{
	.juzhong(100px, 100px);
}
#wrap2{
	.juzhong(100px);
}

css

#wrap1 {
  position: absolute;
  left: 0;
  right: 0;
  top: 100px;
  bottom: 100px;
  margin: auto;
}
#wrap2 {
  position: absolute;
  left: 0;
  right: 0;
  top: 10px;
  bottom: 100px;
  margin: auto;
}

命名参数

less

.juzhong(@c:10px, @h){
	position: absolute;
	left: 0;
	right: 0;
	top: @h;
	bottom: @c;
	margin: auto;
}
#wrap{
	// 指定实参给谁赋值
	.juzhong(@h:100px);
}

css

#wrap {
  position: absolute;
  left: 0;
  right: 0;
  top: 100px;
  bottom: 10px;
  margin: auto;
}

匹配模式

less

.juzhong(L,@c:10px, @h){
	position: absolute;
	left: @h;
	right: @c;
	top: 0;
	bottom: 0;
	margin: auto;
}
.juzhong(R,@c:10px, @h){
	position: absolute;
	left: 0;
	right: 0;
	top: @h;
	bottom: @c;
	margin: auto;
}
#wrap{
	.juzhong(L,@h:100px);//匹配标识符为 L 的样式
}

less

.juzhong(@_){//传 @_ 表示每调用.juzhong就会自动调用,也就是自动加入标记为@_的属性
	position: absolute;
	margin: auto;
}
.juzhong(L,@c:10px, @h){
	left: @h;
	right: @c;
	top: 0;
	bottom: 0;
}
.juzhong(R,@c:10px, @h){
	left: 0;
	right: 0;
	top: @h;
	bottom: @c;
}
#wrap{
	.juzhong(L,@h:100px);//匹配标识符为 L 的样式
}

计算

#wrap{
    width: (50 + 50px);
    height: (100 + 100px);
}

继承

不支持参数

less

.box{
  &:extend(.back);
  background-color: aqua;
}
.back{
  width: 100px;
  height: 100px;
}
.back:hover{
  background-color: red;
}

css

.box {
  background-color: aqua;
}
.back,
.box {
  width: 100px;
  height: 100px;
}
.back:hover {
  background-color: red;
}

extend all

这样写.box会继承.back所有的属性

less

.box{
  &:extend(.back all);
  background-color: aqua;
}

.back{
  width: 100px;
  height: 100px;
}
.back:hover{
  background-color: red;
}

css

.box {
  background-color: aqua;
}
.back,
.box {
  width: 100px;
  height: 100px;
}
.back:hover,
.box:hover {
  background-color: red;
}

避免编译

这样就不会自动编译,识别为字符串,交给浏览器编译。

*{
    padding:~"cacl(100 + 50px)";
}

总结

less这一部分内容还是比较简单的,但是要是想熟练使用,而且还要用的好是需要下功夫的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值