0

我在下面制作了这个 css 代码来为链接创建一个类,并且不将 css 应用于每个 a 标签,而只是应用于具有该类的标签,但它不起作用。

.redlink
{
color: red;
font-family: 'Finger Paint', cursive;  
}

.redlink.a.link
{
text-decoration: none;
color: red;
font-family: 'Finger Paint', cursive;
}

.redlink.a.hover
{
text-decoration: none;
color: orange;
font-family: 'Finger Paint', cursive;
}

.redlink.a.visited 
{
text-decoration: none;
color: red;
font-family: 'Finger Paint', cursive;
}

.redlink.a.active
{
text-decoration: none;
color: red;
font-family: 'Finger Paint', cursive;
}

.redlink.a.
{
text-decoration: none;
color: red;
font-family: 'Finger Paint', cursive;
}

好的,所以我的代码的重点是将类 redlink 作为用于 a 标签的类,这是我第一次尝试这样做。基本上,除了基本的 .redlink 类之外,代码不能正常工作,这里是 html:

<a href="#" class="redlink">I should light up orange!</a>
4

3 回答 3

1

你应该这样写

a.redlink
{
color: red;
font-family: 'Finger Paint', cursive;  
}
a.redlink:hover
{
text-decoration: none;
color: orange;
}
a.redlink:active
{
text-decoration: none;
color: red;
}

演示

此外,您不需要在所有类中编写 font--family,它足以编写一次用于主标记类。

于 2013-05-30T11:24:39.950 回答
0

.在 css 中用于您自己的类,就像您在此处所做的那样:

.redlink
{
color: red;
font-family: 'Finger Paint', cursive;  
}

但是当你开始添加 .behind 的部分是错误的..

如果您想要的不仅仅是这个链接,而是网站某些部分的链接,您可以这样做:

.redlink a:link, .redlink a:visited, .redlink a:active
{
    text-decoration: none;
    color: red;
    font-family: 'Finger Paint', cursive;
}

.redlink a:hover 
{ 
    text-decoration: none; 
    color: orange; 
    font-family: 'Finger Paint', cursive; 
}

如果你有 html:

<div class="redlink">
every <a href="">link</a> in this area will be red
</div>

如果您只希望它用于特定的一个链接,请使用 Somwya 的答案。

于 2013-05-30T11:32:01.310 回答
0

你可以试试这个

.redlink:hover
于 2013-05-30T11:25:47.960 回答