- 如果在某一个选择器的{}中直接写上了其它的选择器, 会自动转换成后代选择器
例如以下代码: .box1 .son - &的作用, 是告诉less在转换的时候不用用后代来转换, 直接拼接在当前选择器的后面即可
.box1 {
width: 400px;
height: 300px;
position: relative;
background-color: pink;
margin-bottom: 20px;
.son {
&:hover {
background-color: skyblue;
}
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #f5f5f5;
}
}
.box2 {
width: 400px;
height: 300px;
background-color: skyblue;
position: relative;
.son {
&::after {
content: '胡歌';
display: block;
width: 150px;
height: 90px;
background-color: pink;
}
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #f5f5f5;
}
}
