css - 访问过的链接有不需要的文字修饰

标签 css css-transitions

我有一个链接,当我将鼠标悬停在它上面时,我希望它可以转换为另一种颜色。但是,当我单击它时,它应该恢复正常,就像我将鼠标悬停在它上面之前一样。

a {
  -o-transition:.3s;
  -ms-transition:.3s;
  -moz-transition:.3s;
  -webkit-transition:.3s;
  transition:.3s;
  text-decoration: none;
  color: #ffffff;
}

a:hover { 
  text-decoration: none;
  color: #66caff; 
}

当我悬停时它工作正常,但在我访问链接后,我得到了不需要的下划线,并且它变成了紫色。它看起来应该和我点击它之前一样。

a:visited { 
  text-decoration: none;
  color: #ffffff; 
}

添加这个可以防止发生任何颜色转换,并且访问过的链接仍然带有下划线。

最佳答案

anchor (链接)上的伪类应该以特定顺序声明。顺序是:链接、已访问、悬停、事件。

将您的 :visited 规则移到 :hover 之前,它将起作用。

片段:

a {
  text-decoration: none; color: #0f0;
  transition: all 0.3s;
}

a:visited { color: #0f0; }
a:hover { color: #f00; }
<a href="#">Link 1</a> | <a href="#">Link 2</a>

引用:https://developer.mozilla.org/en-US/docs/Web/CSS/%3Avisited

...This style may be overridden by any other link-related pseudo-classes, that is :link, :hover, and :active, appearing in subsequent rules. In order to style appropriately links, you need to put the :visited rule after the :link rule but before the other ones, defined in the LVHA-order: :link — :visited — :hover — :active.

关于css - 访问过的链接有不需要的文字修饰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34173627/

相关文章:

jquery - 具有页眉/正文/页脚的可调整大小的 DIV 容器,其中正文可滚动

CSS:给一个div一个高度是一个数字的倍数?

javascript - 如何在使用脚本加载 div 后添加 css?

css - 使用 CSS3 的动画适合屏幕

javascript - ionic 菜单,如何避免默认添加导航图标的隐藏类

html - 使用 CSS 处理自动拉伸(stretch)搜索字段

css - fireFox和Chrome之间图像的transform属性的css过渡渲染的差异

CSS 大小转换保留在父 div 中

CSS3 动画和最佳移动性能

css - 当我将变换原点更改为右侧时,为什么这个 div 会在屏幕上跳跃?