Combine :after with :hover(结合 :after 和 :hover)
问题描述
我想在 CSS(或任何其他伪选择器)中将 :after 与 :hover 结合起来.我基本上有一个列表,并且带有 selected 类的项目具有使用 :after 应用的箭头形状.我希望对于悬停但无法使其正常工作的对象也是如此.这是代码
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
#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>
推荐答案
只需将 :after 附加到您的 #alertlist li:hover 选择器,方法与您对#alertlist li.selected 选择器:
Just append :after to your #alertlist li:hover selector the same way you do with your #alertlist li.selected selector:
#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: "";
}
这篇关于结合 :after 和 :hover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:结合 :after 和 :hover
基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01
