简体   繁体   English

CSS伪选择器:伪之后有效:悬停

[英]CSS Pseudo Selector: Active After Pseudo: Hover

I am trying to get the blue line that is appearing on hover to stay when the link is active. 我试图使链接处于活动状态时悬停时出现的蓝线保持不变。 I am building an angular app with a few different views and when the user is active on a view, I would like the underline I have created on hover, to stay when the link is selected. 我正在构建一个具有几个不同视图的角度应用程序,并且当用户在视图上处于活动状态时,我希望在悬停时创建的下划线在选择链接时保持不变。 I assume it needs to take on an active pseudo selector, but when I've added it in, it cancels the hover. 我认为它需要使用一个活动的伪选择器,但是当我添加它时,它将取消悬停。 Any suggestions on this would be much appreciated. 任何建议对此将不胜感激。

Here is my current code: 这是我当前的代码:

 footer { width: 100%; margin-top: 150px; padding: 0 60px; font-family: "Lora", serif; } footer a { text-decoration: none; color: #ABABAB; } a:after { content: ''; display: block; margin: auto; height: 3px; width: 0px; background: transparent; transition: width .5s ease, background-color .5s ease; } a:hover:after { width: 100%; background: #00FFE9; } .nav-footer { list-style: none; padding: 0; border-top: solid 2px #DEDEDE; display: flex; justify-content: space-between; font-size: 14px; padding: 15px; } 
 <footer> <nav class="nav-footer"> <a ui-sref-active="active" ui-sref="friends">View Friends</a> <a ui-sref-active="active" ui-sref="friend-search">Find Friends</a> <a ui-sref-active="active" ui-sref="update">Update Profile</a> </nav> </footer> 

Here is the jsfiddle: https://jsfiddle.net/uw8fqbyr/ 这是jsfiddle: https ://jsfiddle.net/uw8fqbyr/

ui-sref-active="active" directive adds "active" css class to a tag when selected view is active. 当选定的视图处于活动状态时,ui-sref-active =“ active”指令将“活动” css类添加到标签中。

You should add this css rule 您应该添加此CSS规则

a.active:after {
  width: 100%;
  background: #00FFE9;
}

with

a:active:after {}

you can enable the text decoration for your anchor. 您可以为锚点启用文本修饰。

Try a:active{} 尝试a:active{}

for the <a> tag visited 用于访问的<a>标记

a:visited{}

Try below 试试下面

 footer { width: 100%; margin-top: 150px; padding: 0 60px; font-family: "Lora", serif; } footer a { text-decoration: none; color: #ABABAB; } a:after { content: ''; display: block; margin: auto; height: 3px; width: 0px; background: transparent; transition: width .5s ease, background-color .5s ease; } a:hover:after { width: 100%; background: #00FFE9; } a.active:after { width: 100%; border-bottom: 3px solid #00FFE9; } .nav-footer { list-style: none; padding: 0; border-top: solid 2px #DEDEDE; display: flex; justify-content: space-between; font-size: 14px; padding: 15px; } 
 <footer> <nav class="nav-footer"> <a ui-sref-active="active" ui-sref="friends">View Friends</a> <a class="active" ui-sref-active="active" ui-sref="friend-search">Find Friends</a> <a ui-sref-active="active" ui-sref="update">Update Profile</a> </nav> </footer> 

只需添加以下代码链接,就不会在active状态下显示下划线
a:active { text-decoration: none; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM