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


基础教程推荐
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01