是否可以将父级的属性用作变量?例如,在这段代码中,我希望能够赋予“内盒”元素与其父“盒子”相同的颜色。
使其类似于.inner-box {background-color: $Outer-Parent's-Color;}
<div class="box">
<div class="box1">
<div class = "inner-box">
BOX
</div>
</div>
</div>
<div class="box red">
<div class="box1">
<div class = "inner-box">
RED BOX
</div>
</div>
</div>
和CSS
.box {
width: 100px;
padding: 10px;
margin: 10px;
background-color: blue;
}
.box1 {
background-color: darkblue;
padding: 10px;
}
.box.red {
background-color: red;
}
.box.red .box1 {
background-color: darkred;
}
.inner-box {
background-color: $Outer-Parent's-Color;
}