样式化锚文本(名称)

Styling Anchor Text (a name)

我有这些锚:

<h2><a name="facebook">facebook</a></h2>
<h2><a name="mobilephone">mobilephone</a></h2>

目前文本是蓝色的,因为它是 link。我正在尝试更改颜色,使它们与所有其他 H2 文本相同。

我试过:

.name {
        color:red !important;
    }

:name {
        color:red !important;
    }

:facebook {
    color:red !important;
}

a:name {
    color:red !important;
}

a:facebook {
    color:red !important;
}

a[name=facebook]{
    color:red !important;
}

a[name]{
    color:red !important;
}

CSS 中的属性选择器在这种情况下应该可以工作,但是既然您要设置所有 h2 a 元素的颜色,为什么还需要属性选择器?这还不够吗:

h2 a {
    color: red;
}

jsFiddle Demo

如果必须使用 name 的属性选择器,请使用:

a[name="facebook"],
a[name="mobilephone"] {
    color: red;
}

jsFiddle Demo

要阅读有关 CSS 中属性选择器的更多信息,请参阅 MDN Documentation

如果你想为所有只有 name 但没有链接的锚设置样式,你可以使用类似的东西:

a[name]:not(:link) {
    color: red;
}
<a name="header">Header</a>
<a href="http://gurustop.net">Link</a>

我认为您正在寻找 css 属性 text-decoration 您可以在这里阅读 here:

我对你的问题的解决方案是:

h2 a {
    color:red;
    text-decoration: none;
}

看演示:https://jsfiddle.net/wre1yLvn/

如果你想使用与 h2 完全相同的颜色,你应该使用这个

h2 {
 color: red;
}

h2 > a {
 color: inherit;
}

演示:https://jsfiddle.net/aLncaegh/

试试这个

h2 a:visited {
color: inherit;
}

来源:http://www.w3schools.com/css/css_link.asp