<style>.f-1, .f-1 a {
color: #fff;
}
.f-2, .f-2 a {
color: #000;
}</style>
<body class="f-2">
<ul class="f-1">
<li><a>TEST COLOR</a></li>
</ul>
</body>
因为css中的f-2跟在f-1之后,所以浏览器会将测试颜色呈现为白色(#fff)。我怎么才能让它呈现出最接近的后代呢?
发布于 2016-08-26 13:05:27
我赞同Vivek的建议。规则.f-2 a
和.f-1 a
都有相同的。因此,您必须使您希望在TEST COLOR
上应用的规则更加具体。您可以尝试使用.f-1 > a
或.f-2 .f-1 a
。
发布于 2016-08-26 14:36:42
您可以使用inherit
功能。这可以继承parents属性。
span {
color: blue;
border: 1px solid black;
}
.extra span {
color: inherit;
}
<div>
Here is <span>a span element</span> which is blue, as span elements are set to be.
</div>
<div class="extra" style="color:green">
Here is <span>a span element</span> which is green, because it inherits from its parent.
</div>
<div style="color:red">
Here is <span>a span element</span> which is blue, as span elements are set to be.
</div>
https://stackoverflow.com/questions/39158437
复制相似问题