0

我很难获得 :link 和 :visited 来处理我的链接。我一直在网上搜索几个小时,并阅读了 20 多个相同问题的不同实例。奇怪的是, :hover 和 :active 正在工作。到底是怎么回事?

这是我的样式表中的代码行:

H1 { text-align: center; width:1000px; font-size: 30pt; font-weight: bold; }

a.artlinks:link {color:#40C0FF; text-decoration: none; font-family: Cambria, Arial; }

a.artlinks:visited { color:#FF00FF; text-decoration: none; font-family: Cambria, Arial; }

a.artlinks:hover {color:#98D7F6; text-decoration: none; font-family: Cambria, Arial; }

a.artlinks:active {color:#FF0000; text-decoration: none; font-family: Cambria, Arial; }

当我在我的 .html 中调用它时,代码是:

<h1><a href="helloworld.html" class="artlinks">Hello World!</a></h1>

有没有人有一个解决方案,还有一种更有效的方法来同时提供常见的 a.artlinks 参数?谢谢

4

1 回答 1

1

您的代码需要整理一下,但我就是这样做的(出于演示目的,我从 h1 中删除了 width 属性)。

H1 { 
    text-align: center; 
    font-size: 30pt; 
    font-weight: bold; 
}

a.artlinks {
    text-decoration: none; 
    font-family: Cambria, Arial;
    color:#40C0FF;
}

a.artlinks:visited { 
    color:#FF00FF; 
}

a.artlinks:hover {
    color:#98D7F6; 
}

a.artlinks:active {
    color:#FF0000; 
}

看到这个jsfiddle:http: //jsfiddle.net/lharby/zkb8thck/

由于 a 类具有相同的属性,您可以在 a.artlinks (font-family, text-decoration) 中定义一次。然后可以为 :hover 、 :active 等定义唯一的其他元素。

于 2015-02-09T10:19:20.940 回答