Less笔记

概览

less 是一门 css 预处理语言,它扩展了 css 语言,增加了变量,混合,函数等特征,使css 更易维护和扩展,less可以运行在Node或浏览器。

Koala可以把less文件编译为css文件。

1. 注释

示例:

/*编译后显示*/
//编译后不显示

2. 变量

示例:

//变量
//定义变量
@width:100px;
@height:100px;
//引用变量
.one{
    width: @width;
    height: @height;
    background-color: aqua;
}

3. 混合

示例:

混合
.o {
    width: 100px;
    height: 100px;
}

.one{
    .o;
    background-color: red;
}

.two{
    .o;
    background-color: blue;
}

4. 混合带参数

示例:


//混合带参数
.border(@b-w,@b-s,@b-c){
    border: @b-w @b-s @b-c;
}
.one{
    width: 100px;height: 100px;.border(5px,dotted,red)
}

5. 混合参数有默认值

示例:

//混合参数有默认值
.border(@b-w:5px){//默认值为5px
    border: @b-w solid blue;
}

.one{
    width: 100px;
    height: 100px;
    .border(10px)
}

6. 嵌套

示例 1:

.one{
    width: 500px;
    height: 500px;
    ul{
        width: 500px;
        height: 500px;
        li{
            list-style: none;
            width: 500px;
            height: 20px;
            background-color: red;
            margin-top: 10px;
            a{
                margin-left: 50%;
                color: black;
                text-decoration: none;
            }
        }
    }
}

示例 2:

.one {
    width: 500px;
    height: 500px;

    ul {
        width: 500px;
        height: 500px;
    }

    li {
        list-style: none;
        width: 500px;
        height: 20px;
        background-color: red;
        margin-top: 10px;
    }

    a {
        margin-left: 50%;
        color: black;
        text-decoration: none;
        &:hover{color: green};
    }
}

7. 运算(加减乘除均可使用)

示例:

//运算
@width:100px;
@height:100px;
@color:#000;
.one{
    width: @width+100;//200px
    height: @height+100;//200px
    background-color: @color+100;//#646464;
}

8. @arguments(全选)

示例:

//@arguments
.border(@b-w,@b-s,@b-c){
    border: @arguments;
}
.one{
    width: 100px;height: 100px;.border(5px,dotted,red)
}

9. @import(导入)

示例:

//@import
@import "2.less";

10. 匹配

示例:

//匹配
.aaa(a){
    width: 100px;
    height: 200px;
    background-color: coral;
}

.aaa(b){
    width: 100px;
    height: 200px;
    background-color:green;
}

.one{
    .aaa(b);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值