【问题标题】:Sub Menu visible before hover Plus Sub Menu background uses Parent Hover background悬停前可见的子菜单加子菜单背景使用父悬停背景
【发布时间】:2014-02-13 00:32:08
【问题描述】:

我希望我能对此有所了解。我知道我在这里的某个地方犯了一个菜鸟编码错误,但我似乎无法找到它,而且我的眼睛正在交叉。请帮忙。

因此,即使在悬停之前子菜单也保持可见,并且由于某种原因,每个子菜单项的背景都具有父悬停背景属性,我一生都无法弄清楚原因。

我做了Fiddle

这是你不想访问链接的代码

HTML

<div id="menu">
    <ul>
        <li class="current_page_item"><a href="home.html">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a>
        <ul>
        <li class="style13"><a href="#"><strong>Option 1</strong></a></li>
        <li class="style13"><a href="#"><strong>Option 2</strong></a></li>
        </ul></li>
        <li><a href="#">Comments</a></li>
        <li><a href="#">Contact</a></li>
    </ul>

</div>

CSS

#menu {
width: 740px;
height: 60px;
margin: 0px auto;
padding: 0px 20px 0px 20px;
background: #000033 url(images/menu-wrapper-bg2.png) repeat-x left top;
}

#menu ul {
margin: 0;
padding: 0px 0px 0px 0px;
list-style: none;
line-height: normal;
}

#menu ul li {
float: left;
padding: 0px 0px 0px 0px;
}

#menu ul li a {
display: block;
float: left;
height: 60px;
margin: 0px;
padding: 0px 36px 0px 36px;
line-height: 60px;
letter-spacing: -1px;
text-decoration: none;
text-shadow: 2px 2px 2px #00033;
font-family: 'Abel', sans-serif;    
font-size: 23px;
font-weight: normal;
color: #FFFFFF;
border: none;
text-shadow: 2px 2px 2px #0000FF;
}

#menu .current_page_item a {
text-shadow: 2px 2px 2px #0000FF;
background: #000066;
/* IE10 Consumer Preview */ 
background-image: -ms-linear-gradient(bottom, #000066 0%, #000033 100%);

/* Mozilla Firefox */ 
background-image: -moz-linear-gradient(bottom, #000066 0%, #000033 100%);

/* Opera */ 
background-image: -o-linear-gradient(bottom, #000066 0%, #000033 100%);

/* Webkit (Safari/Chrome 10) */ 
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, 
#000066), color-stop(1, #000033));

/* Webkit (Chrome 11+) */ 
background-image: -webkit-linear-gradient(bottom, #000066 0%, #000033 100%);

/* W3C Markup, IE10 Release Preview */ 
background-image: linear-gradient(to top, #000066 0%, #000033 100%);
}

#menu ul li a:hover {
background: #000066;
text-decoration: none;
text-shadow: 2px 2px 2px #0000FF;
color: #FFFFFF;
/* IE10 Consumer Preview */ 
background-image: -ms-linear-gradient(bottom, #000066 0%, #000033 100%);

/* Mozilla Firefox */ 
background-image: -moz-linear-gradient(bottom, #000066 0%, #000033 100%);

/* Opera */ 
background-image: -o-linear-gradient(bottom, #000066 0%, #000033 100%);

/* Webkit (Safari/Chrome 10) */ 
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0,  
#000066), color-stop(1, #000033));

/* Webkit (Chrome 11+) */ 
background-image: -webkit-linear-gradient(bottom, #000066 0%, #000033 100%);

/* W3C Markup, IE10 Release Preview */ 
background-image: linear-gradient(to top, #000066 0%, #000033 100%);
}
#menu ul li ul li.active a, #menu ul li ul li a:hover {
text-decoration:none;
color:#000066;
text-shadow: 2px 2px 2px #0000FF;
}
#menu ul li ul {
height:500px;
left:289px;
overflow:visible;
position:absolute;
top:69px;
width:160px;
float: left;
}
#menu ul li ul li:hover ul li ul {
left:275px;
top:37px;
padding-top: 2em;
padding-left: .90em;
line-height: 30px!important;

}
#menu ul li ul li {
background: #000066;
border:1px solid #ffffff;
float:none;
height:29px;
margin:-1px 0 0;
padding:0 12px;
position:relative;
width:auto;
z-index:1000;
}
#menu ul li ul li a {
color:#ffffff!important;
font-family:'Abel', sans-serif; 
font-size:20px;
line-height:22px;
text-transform:none;
text-shadow: 2px 2px 2px #0000FF;
font-weight:0;
margin:0;
padding:0;
display:block;
padding-top: 5px;

}
#menu ul li ul li.active a, #menu ul li ul li a:hover {
color:#fff!important;
line-height: 30px!important;

}

【问题讨论】:

  • 悬停前是否隐藏子菜单?如果你是我看不到?
  • 我试过了,但一切都消失了。我没有把它写对,因为下面的答案完全是答案。但是,我仍然遇到具有父悬停背景属性的子菜单项的问题。如果您对此有任何想法,请告诉我。谢谢!

标签: html css hover parent-child submenu


【解决方案1】:

该 CSS 实际上并没有隐藏或显示子菜单。尝试添加:

#menu ul ul {
    display: none;
}
#menu li:hover ul{
    display: block;
}

【讨论】:

  • 太棒了!这有助于在悬停之前隐藏它。谢谢!关于为什么它们的子菜单项采用父悬停背景和行高的任何想法?
  • 你有没有定义不同的东西?请记住ul li 将影响所有li,无论子菜单li 与否。
  • 是的,但是当我将其指定为 ul li ul li 时,应该会更改子菜单属性。它通常出现在我处理过的其他子菜单中。这实际上是我在不同站点上使用的代码,没有任何问题,子菜单根本不具有父悬停属性。
  • 不确定。当我将#menu ul li ul li 声明中的第一条规则调整为background: red; 时,子菜单的背景为红色。 jsfiddle.net/Eb5FH/58
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-04
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 2015-10-18
  • 1970-01-01
相关资源
最近更新 更多