【问题标题】:CSS code a:visited does not workCSS 代码 a:visited 不起作用
【发布时间】:2014-04-04 23:28:43
【问题描述】:

我有一个很菜鸟的问题,所以我希望有人可以帮助我。

我有一个 Blogger 博客,但无法让链接发挥我想要的功能。

我希望帖子内容和侧边栏中的链接 - 带有紫色阴影 (#8B7083) 并带有下划线的链接 - 对于 a:link 和 a:visited 来说看起来相同。出于某种原因,访问过的链接变黑了,尽管我的 CSS 中没有任何地方。

请帮帮我?

【问题讨论】:

    标签: html css hyperlink


    【解决方案1】:

    确实在你的 CSS 中有它:

     .popular-posts .item-title a:link, a:hover, a:active, a:visited {
          color: black !important;
          text-decoration: none !important;
     }
    

    尽量不要使用!important 关键字,它会覆盖所有其他样式。使用特异性来确定应用哪些样式:http://css-tricks.com/specifics-on-css-specificity/

    看看你的选择器,我相信你可能没有按照你的意愿构建它们。你在找这个吗?

      .popular-posts .item-title a:link, .popular-posts .item-title a:hover,  .popular-posts .item-title a:active, .popular-posts .item-title a:visited
    

    就目前而言,您在选择器中的最后三个部分(a:hover、a:active 和 a:visited)正在选择具有这些状态的页面上的 all 链接,因为您没有限制它们通过后代选择器。

    【讨论】:

    • 是的,但这不只适用于流行帖子和物品标题类吗?
    • 不,.popular-posts .item-title a:link 仅用于热门帖子,但您拥有a:hover, a:active, a:visited,这将影响a 样式globally,除非它被覆盖。
    • 谢谢,克里斯和尼克。我没有意识到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    相关资源
    最近更新 更多