我正在尝试创建一个两级水平导航菜单(或菜单栏),当您将鼠标悬停在父菜单项上时,它会显示子子菜单项。如果选择了其中一个子项,则父项具有一个视觉指示符,表明当前页面对应于其子项之一,并且其子项保持显示。
Child2 是当前页面:
parent1 *parent2* parent3
|
child1 *child2* child3
当我将鼠标悬停在 parent1 或 parent3 上时,他们的孩子会根据需要显示。我的挑战是,当显示其他父母的孩子时,我无法弄清楚如何隐藏 parent2 的孩子。有没有 CSS 方法来实现这一点?我知道当鼠标移出 parent2 和 parent2 的孩子时,我可以使用 jquery 来隐藏 parent2 的孩子,但我宁愿不必使用 javascript 以获得最大的可用性。
这是一个活生生的例子
CSS:
ul.AspNet-Menu
{
position: relative;
}
ul.AspNet-Menu,
ul.AspNet-Menu ul
{
margin: 0;
padding: 0;
display: block;
}
ul.AspNet-Menu li
{
position: static;
list-style: none;
float: left;
}
ul.AspNet-Menu li a,
ul.AspNet-Menu li span
{
display: block;
text-decoration: none;
}
ul.AspNet-Menu ul
{
visibility: hidden;
position: absolute;
}
ul.AspNet-Menu li:hover ul ul,
ul.AspNet-Menu li.AspNet-Menu-Hover ul ul
{
visibility: hidden;
}
ul.AspNet-Menu li:hover ul,
ul.AspNet-Menu li li:hover ul,
ul.AspNet-Menu li li li:hover ul,
ul.AspNet-Menu li.AspNet-Menu-Hover ul,
ul.AspNet-Menu li li.AspNet-Menu-Hover ul,
ul.AspNet-Menu li li li.AspNet-Menu-Hover ul
{
visibility: visible;
}
.main-nav2 .AspNet-Menu-Horizontal{
margin: 0;
padding: 0;
font: bold 13px/16px Arial, sans-serif;
position: absolute;
top: 21px;
left: 290px;
}
.main-nav2 ul.AspNet-Menu li {
display: inline;
}
.main-nav2 ul.AspNet-Menu li a,
.main-nav2 ul.AspNet-Menu li span.AspNet-Menu-NonLink {
color: #fff;
background: url(../../nav-bg.gif) no-repeat 0 -24px;
height: 24px;
text-decoration: none;
margin: 0 1px 0 0;
}
.main-nav2 ul.AspNet-Menu li a span,
.main-nav2 ul.AspNet-Menu li span.AspNet-Menu-NonLink span {
background: url(../../nav-bg-right.gif) no-repeat 100% -24px;
padding: 4px 12px 4px 12px;
cursor: pointer;
}
.main-nav2 ul.AspNet-Menu li a:hover,
.main-nav2 ul.AspNet-Menu li a.active {
background-position: 0 0;
color: #1b8db3;
}
.main-nav2 ul.AspNet-Menu li a:hover span,
.main-nav2 ul.AspNet-Menu li a.active span {
background-position: 100% 0;
}
.main-nav2 ul.AspNet-Menu li.AspNet-Menu-Selected a,
.main-nav2 ul.AspNet-Menu li.AspNet-Menu-ChildSelected a
{
background-position: 0 0;
color: #1b8db3;
}
.main-nav2 ul.AspNet-Menu li.AspNet-Menu-Selected a span,
.main-nav2 ul.AspNet-Menu li.AspNet-Menu-ChildSelected a span
{
background-position: 100% 0;
}
.main-nav2 ul.AspNet-Menu li.AspNet-Menu-ChildSelected ul
{
visibility: visible;
}
.main-nav2 ul.AspNet-Menu ul{
width:500px;
}
.main-nav2 ul.AspNet-Menu ul li {
font: 12px/20px Arial, sans-serif;
padding: 0 5px 0 0;
display: inline;
}
.main-nav2 ul.AspNet-Menu ul li a {
text-decoration: none;
color: #1b8db3;
padding: 0 0 0 12px;
background-image:none;
}
.main-nav2 ul.AspNet-Menu ul li a:hover {
text-decoration: underline;
}
HTML:
<div class="main-nav2" id="ctl00_MainMenu">
<div class="AspNet-Menu-Horizontal">
<ul class="AspNet-Menu">
<li class="AspNet-Menu-Item">
<a href="javascript:return false;#1">
<span> A Menu Option</span></a>
<ul>
<li class="AspNet-Menu-Item">
<a href="/CSSMenu/A1.aspx">
A1 SubMenu Option</a>
</li>
<li class="AspNet-Menu-Item">
<a href="/CSSMenu/A2.aspx">
A2 SubMenu Option</a>
</li>
</ul>
</li>
<li class="AspNet-Menu-Item">
<a href="javascript:return false;">
<span> B Menu Option</span></a>
<ul>
<li class="AspNet-Menu-Item">
<a href="/CSSMenu/B1.aspx">
B1 SubMenu Option</a>
</li>
<li class="AspNet-Menu-Item">
<a href="/CSSMenu/B2.aspx">
B2 SubMenu Option</a>
</li>
</ul>
</li>
<li class=" AspNet-Menu-Selected">
<a href="/CSSMenu/C.aspx">
<span> C Menu Option</span></a>
</li>
</ul>
</div>
</div>
非常感谢您提供任何提示或帮助!
特里