less的混合:
代码语言:javascript复制<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
/*混合名称的核心是:是定义一个名称,名称里面是双方都具备的代码
注意一下:如果加括号代码
*/
/*.center
{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
.center()
{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
.father
{
width: 300px;
height: 300px;
background: red;
.center();
.son
{
width: 200px;
height: 200px;
background: yellow;
.center();
}
}*/
/*加括号编译后的*/
.center {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.father {
width: 300px;
height: 300px;
background: red;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.father .son {
width: 200px;
height: 200px;
background: yellow;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
带参数的混合:
代码语言:javascript复制<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
/*.whc(@w,@h,@c)
{
width: @w;
height: @h;
background: @c;
}
.whc(@w:100px,@h:100px,@c:pink)
{
width: @w;
height: @h;
background: @c;
}
.box1
{
/*.whc(200px,200px,red);*/
/*.whc(@c:red);
}
.box2
{
.whc(200px,200px,blue);
}*/
/*编译后的*/
.box1 {
/*.whc(200px,200px,red);*/
width: 100px;
height: 100px;
background: red;
}
.box2 {
width: 200px;
height: 200px;
background: blue;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
记住,如果要·指定的话,名称加上值就行了
代码语言:javascript复制.whc(@c:red);