【问题标题】:CSS link color style overwriteCSS链接颜色样式覆盖
【发布时间】:2013-05-06 05:07:15
【问题描述】:

我完全生气了!我希望有人能给我添加一个很好的提示来解决这个问题。

所以...我创建了 2 个 div,在这两个 div 里面是一个不同颜色的 LINK。一切正常,但是当我更改覆盖我的第一个链接的第二个链接颜色时......几乎每次我遇到这个问题......

我的css代码:

.button a, a:link, a:visited { text-decoration:none; font-size:12px; color:#FFF; }
.button a:hover { cursor:pointer; color:#FFF; }

.post-share-comment a, a:link, a:visited { font-size:12px; color:#000; }
.post-share-comment a:hover { cursor:pointer; }

我的 .button 链接颜色是白色的,但在网络上不是......其他链接也是白色的...所以 第二种样式会覆盖第一种样式 ???为什么是这样 ???

谢谢!!!!

【问题讨论】:

    标签: html css colors hyperlink styles


    【解决方案1】:

    逗号分解完整的选择器,而不是它们的组件

    这个:

     .post-share-comment a, a:link, a:visited {}
    

    意思:

     .post-share-comment a {}
     a:link {}
     a:visited {}
    

    不是:

     .post-share-comment a {}
     .post-share-comment a:link {}
     .post-share-comment a:visited {}
    

    你的选择器应该是:

     .post-share-comment a,
     .post-share-comment a:link,
     .post-share-comment a:visited {}
    

    如果您不想写出完整的语法,那么您可以使用 LESS 等预处理程序,这将允许:

     .post-share-comment {
         a,
         a:link,
         a:visited {}
     }
    

    【讨论】:

    • 天啊! :D 这行得通!非常感谢。我学错了>_
    • @user1938141 接受解决您问题的答案始终是一个好习惯。它可以帮助其他人在遇到相同问题时轻松找到解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多