简体   繁体   English

将鼠标悬停在子菜单上时,保持css菜单的父项处于活动状态

[英]keep css menu parent item active when hovering over sub menu

I have this css menu with sub items, how can i keep the menu item active (have a different background color) when hovering over the sub items? 我有带子项的CSS菜单,将鼠标悬停在子项上时如何保持菜单项处于活动状态(背景颜色不同)?

current CSS code: 当前的CSS代码:

#nav {
    background-color:#F36F25;
    margin:14px 0 0 0;
    width: 100%;
    height:35px;
    left:0;
}
#nav>li {
    float:left;
    list-style:none;
}
#nav li:hover ul {
    position:absolute;
    display:block;
}
#nav li a {
    display: inline-block;
    padding: 8px;
    margin:0;
    background: #F36F25;
    text-decoration: none;
    color: #FFFFFF;
    border-right:1px solid #F36F25;
}
#nav li a:hover, #nav li a.active {
    background: #666666;
    cursor:pointer;
}
#nav li ul {
    position:absolute;
    display: none;
    list-style:none;
    margin:0;
}
#nav li ul li {
    margin-top:0;
    margin-right:0;
    margin-bottom:0;
    margin-left:-40px;
}
#nav li ul li a {
    background-color: #F36F25;
    color:#FFFFFF;
    border:1px solid #F36F25;
    width:145px;
}
#nav li ul li a:hover {
    background-color: #666666;
    border:1px solid #f36f25;
}
.clearfix:after {
   content: " "; /* Older browser do not support empty content */
   visibility: hidden;
   display: block;
   height: 0;
   clear: both;
}
.clearfix:after {
  content: "";
  display: table;
  clear: both;
}

here is a fiddle with the fulle code too: http://jsfiddle.net/dumJd/ 这也是带有完整代码的小提琴: http : //jsfiddle.net/dumJd/

Try this code here on line 25: 在第25行尝试以下代码:

#nav li:hover > a, #nav li a.active {
  background: #666666;
  cursor:pointer;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将鼠标悬停在菜单和子菜单上 - Hovering over menu and sub menu CSS Animation on Menu item is not working when hovering - CSS Animation on Menu item is not working when hovering CSS3 Flip下拉菜单-将鼠标悬停在子菜单上时保留主菜单悬停样式 - CSS3 Flip Dropdown Menu - Retain main-menu hover style when hovering over sub-menu 将鼠标悬停在vuejs中的父菜单或子菜单上时如何继续显示动态子菜单? - How to keep showing the dynamic submenu when hovering over parent menu or submenu in vuejs? 将鼠标悬停在子菜单上后,为父菜单项设置不同的颜色 - Set different color to parent menu item after hovering over submenu 当鼠标悬停在CSS上时,为什么我的第一个子菜单没有出现? - Why does my first sub-menu not appear when the mouse is hovering over it in CSS? 删除父级的CSS格式 <li> 悬停在孩子身上时 <li> 在下拉菜单中 - remove CSS formating of parent <li> when hovering over child <li> in dropdown menu CSS / JQuery:将鼠标悬停在另一个列表项上时,菜单列表标题会下拉 - CSS/JQuery: Menu List Titles Drop Down When Hovering Over Another List Item CSS下拉子菜单未放在父菜单项下 - css dropdown sub menu not dropping under parent menu item 菜单项悬停时,子菜单不会显示(css html) - Sub menu wont show when menu item hovered over (css html)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM