2

我正在尝试实现每个 div 具有不同的超链接样式。我有一个整体的超链接样式,然后是一个 div,我希望该 div 中的所有超链接具有完全不同的样式。我只是不确定如何编写css。任何帮助都是极好的。

a {color:#d85d5d; font-weight:bold; text-decoration:none;}
a:hover {color:#222; text-decoration:underline;}

.SingleLink
{
    #a
    #a:{
        text-decoration: underline;
    }

    #a:link {
        color: #0000FF;
    }

    #a:visited {
        color: #660099;
    }

    #a:active {
        color #FF0000;
    }

    #a:hover {
        font-weight: bold;
    }

}

所以基本上我页面中的所有内容都有第一个 a 然后 .SingleLink div 中的任何内容都有不同的超链接样式。

谢谢!

4

2 回答 2

3

您需要为每个规则指定 .SingleLink 选择器,如下所示:

.SingleLink a:link { color: #0000FF; }

.SingleLink a:visited { color: #660099; }

.SingleLink a:active { color #FF0000; }

.SingleLink a:hover { font-weight: bold; }

使用 {} 在选择器下对规则进行分组仅对一些 CSS 预处理器(如LESS)有效,但作为“纯”CSS 无效。

于 2013-03-27T14:10:13.857 回答
3

您需要为每个类使用类名,不能像在示例中使用纯 CSS 那样包装它们。

使用下面的代码应该可以解决这个问题:

.SingleLink a {  text-decoration: underline; }

.SingleLink a:link { color: #0000FF; }

.SingleLink a:visited { color: #660099; }

.SingleLink a:active { color #FF0000; }

.SingleLink a:hover { font-weight: bold; }
于 2013-03-27T14:10:00.753 回答