如何在不更改或删除父选择器的情况下使此链接使用子选择器? (我希望链接是蓝色的。)
<html>
<head>
<style>
.parent a { color:Red; }
.child { color:Blue; }
</style>
</head>
<body>
<div class="parent">
<a class="child" href="http://www.stackoverflow.com">
stackoverflow
</a>
</div>
</body>
</html>
令我惊讶的是,在这种情况下,父级覆盖了子级!
最佳答案
使用a.child
作为选择器。
<html>
<head>
<style>
.parent a { color:Red; }
a.child { color:Blue; }
</style>
</head>
<body>
<div class="parent">
<a class="child" href="http://www.stackoverflow.com">
stackoverflow
</a>
</div>
</body>
</html>
关于CSS 继承 : Overriding a parent selector that is a descendant selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2345003/