LESS
// 不会被编译
/**/ 会被编译
@bgColor:yellow;
.border{
border:2px solid pink;
}
h1{
width:80%;
height:60px;
.border;
color: #000;
background:@bgColor;
span{
font-size: 12px;
font-weight: 700;
}
}
nav.top{
    background:#333;
    height: 50px;
    ul{        
        display: flex;
        width:960px;
        height: 50px;
        margin: 0 auto;
        li{
            a{
                display: block;
                line-height: 50px;
                padding:0 20px;
                color: #fff;
                &:hover{
                    color: #000;
                }
            }
            &:hover{
                background:pink;  //表示鼠标悬浮在li元素上的颜色改变
            } 
        }
        /* li:hover{
            background:pink;   
        } */
         
    }
}
@w:960px;
.box{
width:@w/2 - 100;
}
.title{
    font-family: '楷体';
    font-size:20px;
    background: pink;
}
.box{
    width:100px;
    height:100px;
    .title;
}
5.1 混合(带参数,传递参数)
.border(@borderWidth:1px,@borderColor:#ccc){
    border:@borderWidth solid @borderColor;
}
.box{
    .border(10px,#000);
    width:100%;
    height:50px;
}
.box2{
    width:400px;
    height:400px;
    .border(5px,red);
}
//bootstrap3以及之前版本基于less开发的,之后版本基于sass开发的
//公共样式 @_表示公共样式
.btn(@_){
display:inline-block;
text-align: center;
background: #09c;
color: #fff;
}
.btn(sm){
padding:3px 8px;
font-size: 14px;
border-radius: 2px;
box-shadow: 3px 3px 3px #333;
}
.btn(md){
padding:4px 10px;
font-size: 16px;
border-radius: 4px;
box-shadow: 4px 4px 4px #333;
}
.btn(lg){
padding:5px 15px;
font-size: 18px;
border-radius: 4px;
box-shadow: 5px 5px 5px #333;
}
.btn(@_,@bgColor,@color){
    display:inline-block;
    text-align: center;
}
.btn(sm,@bgColor,@color){
    padding:3px 8px;
    font-size: 14px;
    border-radius: 2px;
    box-shadow: 3px 3px 3px #333;
    background: @bgColor;
    color: @color;
}
.btn(md,@bgColor,@color){
    padding:4px 10px;
    font-size: 16px;
    border-radius: 4px;
    box-shadow: 4px 4px 4px #333;
    background: @bgColor;
    color: @color;
}
.btn(lg,@bgColor,@color){
    padding:5px 15px;
    font-size: 18px;
    border-radius: 4px;
    box-shadow: 5px 5px 5px #333;
    background: @bgColor;
    color: @color;
}
//调用匹配
.btn1{
    .btn(lg,#000,#fff);
}
.box{
    width:'~100px + 300px*2px';
}
.border(@borderWidth,@borderStyle,@borderColor){
    border:@borderWidth @borderStyle @borderColor;
    border:@arguments;
}
.box{
    .border(1px,solod,red);
}
Sass
//sass,不兼容css,且语法严格
$width: 200px; //必须有空格
.box
width: $widtg
height: 500px
//scss 兼容css语法
$color:red;
.box{
background: $color;
}
//scss全局变量与局部变量
$color:pink; //全局变量
.box{
$bgcolor:yellow; //局部变量
color:$color;
background: $bgcolor;
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!