CSS active selector using after pseudo element

拥有回忆 提交于 2021-01-20 07:59:28

问题


I have a problem to achieve on active icon selector on after pseudo selector. Below is the code which am tried.

<html>
<head>
<style type="text/css">
.btn{
width:25%;          
}
.name{
background: #fff;
color: #000;
text-align: center;
height: 35px;
line-height: 35px;
font-size: 18px;
border: 1px solid;  
} 
.name:after{
content: "";
position: absolute;
left: 210px;
top: 19px;
background-image: url('dark.png');
width: 15px;
height: 15px;
background-size: 100% auto; 
}
.name:after:active{
background-image: url('light.png');
}
</style>
</head>
<body>
<div class="btn name">Submit</div>
</body>
</html>

LightDark

suggest me the approach to achieve the active selector using after pseudo selector. Thanks in advance.


回答1:


The pseudo-element needs to come last:

.name:active:after{
background-image: url('light.png');
}

If you're looking to change the pseudo-element style only when the pseudo-element is activated, that's not possible. See this answer for an explanation.



来源:https://stackoverflow.com/questions/22985737/css-active-selector-using-after-pseudo-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!