less的使用技巧

187 阅读1分钟

less的使用技巧非常多,今天写两个:

一、&符号代表&所在的大括号直接上级的class节点;


.box{
    &.list{ 
        background:blue;
    }
    &:hover{
        background:blue;
    }
}

等同于

.box.list{ 
    background:blue;
}
.box:hover{
    background:blue;
}

二,not的使用

.box{
    &:not(.big){
        background:yellow;
    }
}

等同于:

.box:not(.big){
    background:yellow;
}

即class为box的盒子,并且class不是big的,背景色为黄色;