【问题标题】:CSS sliding underline on hover - color transition does not work on a visited link悬停时的 CSS 滑动下划线 - 颜色过渡不适用于已访问的链接
【发布时间】:2015-04-21 01:08:54
【问题描述】:

我创建了一个导航,在悬停时为链接添加下划线(从中间开始向外滑动下划线),并将链接从深绿色转换为浅绿色。这完全没问题,除非单击其中一个链接并变成“已访问”链接:当我重新单击已访问链接时,滑动下划线仍然有效,但颜色不会从深绿色变为浅绿色,它只是保持为深绿色。我已经尝试了所有我能想到的方法,但无法获得访问过的链接来像未访问过的链接一样转换它的颜色。

HTML:

<div id="topNavigation">
    <ul>
        <li><a href="encyclopedia.html">ENCYCLOPEDIA</a></li>
        <li><a href="journal.html">JOURNAL</a></li>
        <li><a href="society.html">SOCIETY</a></li>
        <li><a href="about.html">ABOUT</a></li>
    </ul>
</div>

CSS:

#topNavigation a:link {
    font-family:"Quicksand-Regular", "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    font-size:20px;
    position:relative;
    color:#00590d;
    text-decoration:none;
    transition:color .35s;
    -webkit-transition:color .35s;
}

#topNavigation a:hover {
    color:#7ead34;
}

#topNavigation a:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 2px;
  bottom: 0;
  left: 0;
  background-color: #7ead34;
  visibility: hidden;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transition: all 0.3s ease-in-out 0s;
  transition: all 0.3s ease-in-out 0s;
}

#topNavigation a:hover:before {
  visibility: visible;
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
}

#topNavigation a:visited {
    color:#00590d;
    text-decoration:none;
}

你可以在这里看到我在说什么: http://www.religionandnature.com/website2015/

访问了百科全书页面的链接,但颜色没有变化。其他链接没有被访问并且工作正常。任何建议表示赞赏。

【问题讨论】:

  • 也许可以尝试使用 RGB 而不是十六进制。

标签: css sliding visited


【解决方案1】:

目前:visited 声明位于:hover 之下。这意味着:visited 颜色将始终覆盖悬停颜色。

Use the LVHA order — 链接、访问、悬停、激活!

:visited CSS 伪类允许您仅选择具有 被访问过。此样式可能会被任何其他与链接相关的 伪类,即:link、:hover 和:active,出现在 后续规则。 为了给链接设置合适的样式,您需要 将 :visited 规则放在 :link 规则之后,但在其他规则之前, 在 LVHA-order 中定义: :link — :visited — :hover — :active.

悬停颜色现在将覆盖访问的颜色。

像这样:

#topNavigation a:link {}
#topNavigation a:visited {}/*Place before :hover*/
#topNavigation a:hover {}
#topNavigation a:before {}
#topNavigation a:hover:before {}

【讨论】:

  • 是的!太感谢了。 CSS 的顺序总是让我发疯。现在完美运行。
  • 嗨@DanielWhittaker!很高兴这解决了问题:) 请通过单击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
猜你喜欢
  • 1970-01-01
  • 2015-08-01
  • 2012-02-03
  • 2021-05-22
  • 2016-02-15
  • 2012-09-19
  • 2016-12-21
  • 2013-05-09
  • 2013-09-04
相关资源
最近更新 更多