【发布时间】:2014-07-28 14:12:42
【问题描述】:
我有一个如下所示的菜单:http://i.stack.imgur.com/beX6i.png
小三角形是使用 ::before 制作的。当子菜单的第一个子菜单处于活动状态时,我需要将其更改为悬停的颜色(具有从 js 自动添加的 .active 类)
选择器应该是什么样的?类似 .submenu a:first-child.active?
CSS:
.submenu{
z-index:10;
position:absolute;
display:none;
background:#2b2b2b;
}
.submenu a{
font-family:'Roboto Slab';
display:block;
color:white;
background:transparent;
text-decoration:none;
text-transform:uppercase;
line-height:58px;
padding-left:8px;
padding-right:8px;
font-weight:bold;
font-size:14px;
}
.submenu a:hover{
color:#fe4817;
display:block;
background-color:#3A3939;
}
.submenu a.active{
color:#fe4817;
background-color:#3A3939;
}
.submenu a:first-child:before,
.submenu a:first-child::before{
position:absolute;
top:-8px;
left:0;
content:' ';
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-bottom: 15px solid #2b2b2b;
}
.submenu a:first-child:hover:before,
.submenu a:first-child:hover::before{
border-bottom: 15px solid #3A3939;
}
【问题讨论】:
-
你能提供html标记吗?或者更好的是,一个小提琴来展示你的问题?
-
当子菜单的第一个子项(子菜单 a:first-child)具有 .active 类时,我基本上不知道如何选择 ::before 三角形
-
您似乎知道应该如何做到这一点(从您的帖子中)...您尝试过吗?