less常用
body{font-size: 20px;}
/*我是被编译的*/
//我是不被编译的
/*变量*/
@testWidth:300px;
.div{width: @testWidth}
/*混合 就是复用别的样式,加入自己独特的样式,DIV1的样式和DIV基本一样,多了个border*/
.border{border:5px solid #000}
.div1{
height:29px;
.div;
.border;
}
/*混合带参数*/
.border2(@border_width)
{
border:@border_width solid #ccc;
}
.div3{
.border2(25px)
}
/*混合带默认参数*/
.border3(@border_width:10px)
{
border: @border_width solid #ccc;
}
.div4{
.border3()
}
/*css3兼容性混合列子*/
.borderRadius(@radius:5px)
{
-webkit-border-radius:@radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
.div5{
height: 30px;
width: 30px;
.borderRadius(3px);
}
/*三角*/
.triangle(top,@w:15px,@c:#ccc )
{
border-width:@w;
border-color:transparent transparent @c transparent;
border-style:dashed dashed solid dashed;
}
.triangle(bottom,@w:15px,@c:#ccc )
{
border-width:@w;
border-color:@c transparent transparent transparent;
border-style:solid dashed dashed dashed;
}
.triangle(left,@w:15px,@c:#ccc )
{
border-width:@w;
border-color:transparent @c transparent transparent;
border-style:dashed solid dashed dashed;
}
.triangle(right,@w:15px,@c:#ccc )
{
border-width:@w;
border-color:transparent transparent transparent @c;
border-style:dashed dashed dashed solid;
}
//@_ 代表无论上边选了谁,都带着这个内容
.triangle(@_,@w:15px,@c:#ccc)
{
width: 0;
height:0;
overflow: hidden;
}
//调用
.sanjiao{
.triangle(bottom,30px,red);
}
/*运算*/
@test:300px;
.test{
width: @test+20*5;
}
/*嵌套*/
.list{
width: 600px;
li{
float:left;
p{
width:100px;
};
&_content{
color:red;
}
}
a{
text-align: center;
//&代表他的上一层选择器
&:hover{
color:red;
}
}
.ly{
width: 111px;
&_ly{
width: 121px;
}
}
}
/*避免编译,比如calc这种*/
.cc{
width: calc(300px-30px);
}
.cc{
width: ~'calc(300px-30px)';
}