假设我们有这个:
.first-class {
background: purple;
font-weight: bold;
color: white;
}
.first-class > .second-class {
/* code goes here */
}
在.second-class中,是否可以仅从一等(例如background)继承一个属性,而将其他属性保留为默认属性?
答案 0 :(得分:1)
没有。你必须重置它们。作为.first-class
的父级的.second-class
将继承其继承权。
以下是 WORKING EXAMPLE ,用于说明重置前的方案。
现在当你 reset it.
时在重置之前和之后找到以下代码。
HTML:
<div class="first-class">
<div class="second-class">abcd</div>
</div>
CSS:
.first-class {
background: purple;
font-weight: bold;
color: white;
}
.first-class > .second-class {
/* code goes here */
}
HTML:
<div class="first-class">
<div class="second-class">abcd</div>
</div>
CSS:
.first-class {
background: purple;
font-weight: bold;
color: white;
}
.first-class > .second-class {
background: inherit;
font-weight:normal;
color:black;
}