CSS 继承 : Overriding a parent selector that is a descendant selector

标签 css inheritance css-selectors

如何在不更改或删除父选择器的情况下使此链接使用子选择器? (我希望链接是蓝色的。)

<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/

相关文章:

css - 如何用 6 个和 8 个三 Angular 形制作响应式六边形

html - 如何在angular2中加载图像

java - Java 中泛型类型的子类

wpf - FrameworkElement 的 DataContext 属性不会沿元素树继承

css - 选择没有 i 子节点的 anchor

html - 为什么 CSS 部分 :only-child selector not work?

CSS 选择器后代选择器

html - 背景图像的边框以及滚动

css - wordpress 中的 twitter bootstrap 下拉菜单出现在 revslider 后面

Python __metaclass__ 继承问题