CSS 结合 :after 和 :hover
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13233991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Combine :after with :hover
提问by Chris
I want to combine :after
with :hover
in CSS (or any other pseudo selector). I basically have a list and the item with the selected
class has an arrow shape applied using :after
. I want the same to be true for objects that are being hovered over but cant quite get it to work. Heres the code
我想结合:after
使用:hover
的CSS(或任何其他伪选择器)。我基本上有一个列表,并且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>
回答by BoltClock
Just append :after
to your #alertlist li:hover
selector the same way you do with your #alertlist li.selected
selector:
只需: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: "";
}
回答by Erez Lieberman
in scss
在 scss 中
&::after{
content: url(images/RelativeProjectsArr.png);
margin-left:30px;
}
&:hover{
background-color:$turkiz;
color:#e5e7ef;
&::after{
content: url(images/RelativeProjectsArrHover.png);
}
}
回答by Kishore Kumar
#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: "";
}?