我想在CSS (或任何其他伪选择器)中结合使用:after和:hover。基本上,我有一个list,并且使用:after应用了selected类的项目的箭头形状。我希望同样的情况也适用于悬停在上面的对象,但不能完全让它工作。下面是代码
#alertlist {
list-style: none;
width: 250px;
}
#alertlist li {
padding: 5px 10px;
border-bottom: 1px solid #e9e9e9;
position: relative;
}
#alertlist li.selected,
#alertlist li:hover {
color: #f0f0f0;
background-color: #303030;
}
#alertlist li.selected:after {
position: absolute;
top: 0;
right: -10px;
bottom: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #303030;
content: "";
}<ul id="alertlist">
<li>Alert 123</li>
<li class="selected">Alert 123</li>
<li>Alert 123</li>
</ul>
发布于 2012-11-05 22:22:28
只需将:after附加到#alertlist li:hover选择器,就像处理#alertlist li.selected选择器一样:
#alertlist li.selected:after, #alertlist li:hover:after
{
position:absolute;
top: 0;
right:-10px;
bottom:0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #303030;
content: "";
}发布于 2013-12-27 04:58:58
在scss中
&::after{
content: url(images/RelativeProjectsArr.png);
margin-left:30px;
}
&:hover{
background-color:$turkiz;
color:#e5e7ef;
&::after{
content: url(images/RelativeProjectsArrHover.png);
}
}发布于 2012-11-05 22:27:27
#alertlist li:hover:after,#alertlist li.selected:after
{
position:absolute;
top: 0;
right:-10px;
bottom:0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #303030;
content: "";
}jsFiddle Link
https://stackoverflow.com/questions/13233991
复制相似问题