206

我想:after:hoverCSS(或任何其他伪选择器)结合使用。我基本上有一个列表,并且selected该类的项目有一个使用:after. 我希望对于悬停但无法使其正常工作的对象也是如此。这是代码

#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>

4

4 回答 4

272

只需像使用选择器一样附加: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: "";
}
于 2012-11-05T14:22:27.987 回答
24

在scss中

&::after{
content: url(images/RelativeProjectsArr.png);
margin-left:30px;
}

&:hover{
    background-color:$turkiz;
    color:#e5e7ef;

    &::after{
    content: url(images/RelativeProjectsArrHover.png);
    }
}
于 2013-12-26T20:58:58.370 回答
8
 #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 链接

于 2012-11-05T14:27:26.797 回答
1

cssSelector :hover::after,

cssSelector :hover::before

假设我们有一个标签

a:hover::after {
    /*CSS Property*/
}
a:hover::before {
    /*CSS Property*/
}
于 2022-01-15T17:12:54.843 回答