我正在尝试使用CSS创建垂直菜单。当我将鼠标悬停在子菜单项上时,其中一半的子菜单不会显示。请参阅下图:
可能会发生这种情况,因为蓝色背景中的div和包含菜单的div都位于绝对位置。您可以在此处查看代码:https://jsfiddle.net/02vc01cw/2/
您能否告诉我如何使子菜单正常显示? 提前谢谢。
这是我的代码:
#bg {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 0;
overflow: hidden;
background-color: #437DCC;
}
#drawer {
z-index: 2;
overflow: hidden;
height: 100%;
width: 270px !important;
position: absolute;
overflow: hidden;
}
#gnavi-links > ul {
list-style-type: none;
background: #fff;
}
#gnavi-links > ul > li {
margin-bottom: 10px;
}
#gnavi-links > ul > li > a {
display: block;
height: 40px;
line-height: 40px;
color: #1a1a1a;
font-family: 'Calibre-Bold', sans-serif;
font-weight: bold;
letter-spacing: 0.25em;
text-transform: uppercase;
}
#gnavi-links > ul > li > ul {
list-style-type: none;
margin-left: -50px;
margin-right: 5px;
}
#gnavi-links > ul > li> ul > li > a {
font-size: 13px;
display: block;
padding: 5px 16px;
color: #1a1a1a;
text-decoration: none;
letter-spacing: 0.20em;
text-transform: uppercase;
}
#gnavi-links > ul > li> a:hover {
color: #19a69a;
}
#gnavi-links > ul > li> ul > li a:hover {
background-color: #5A5959;
color: #fff;
}
#gnavi-links > ul > li> ul > li ul {
display: none;
}
#gnavi-links > ul > li> ul > li:hover ul {
position: absolute;
display: block;
background: #999;
margin-left: 170px;
margin-top: -25px;
}
#gnavi-links > ul > li> ul > li > ul > li {
width: 150px;
}

<div id="drawer">
<nav class="drawer-nav" id="gnavi-links" role="navigation">
<ul>
<li><a>Menu Item</a></li>
<li>
<a>Menu Item</a>
<ul>
<li><a>Sub Menu Test 1</a></li>
<li>
<a>Sub Menu Test 2</a>
<ul>
<li><a>Sub Menu Test 1</a></li>
<li><a>Sub Menu Test 2</a></li>
<li><a>Sub Menu Test 3</a></li>
</ul>
</li>
<li><a>Sub Menu Test 3</a></li>
</ul>
</li>
<li><a>Menu Item</a></li>
</ul>
</nav>
</div>
<div id="bg">
</div>
&#13;
答案 0 :(得分:2)
删除overflow: hidden
#drawer
#drawer {
z-index: 2;
height: 100%;
width: 270px !important;
position: absolute;
}
答案 1 :(得分:1)
这是因为你的代码中有overflow:hidden
,删除它并且它会起作用:
#bg {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background-color: #437DCC;
}
#drawer {
z-index: 2;
height: 100%;
width: 270px !important;
position: absolute;
}
#gnavi-links > ul {
list-style-type: none;
background: #fff;
}
#gnavi-links > ul > li {
margin-bottom: 10px;
}
#gnavi-links > ul > li > a {
display: block;
height: 40px;
line-height: 40px;
color: #1a1a1a;
font-family: 'Calibre-Bold', sans-serif;
font-weight: bold;
letter-spacing: 0.25em;
text-transform: uppercase;
}
#gnavi-links > ul > li > ul {
list-style-type: none;
margin-left: -50px;
margin-right: 5px;
}
#gnavi-links > ul > li> ul > li > a {
font-size: 13px;
display: block;
padding: 5px 16px;
color: #1a1a1a;
text-decoration: none;
letter-spacing: 0.20em;
text-transform: uppercase;
}
#gnavi-links > ul > li> a:hover {
color: #19a69a;
}
#gnavi-links > ul > li> ul > li a:hover {
background-color: #5A5959;
color: #fff;
}
#gnavi-links > ul > li> ul > li ul {
display: none;
}
#gnavi-links > ul > li> ul > li:hover ul {
position: absolute;
display: block;
background: #999;
margin-left: 170px;
margin-top: -25px;
}
#gnavi-links > ul > li> ul > li > ul > li {
width: 150px;
}
<div id="drawer">
<nav class="drawer-nav" id="gnavi-links" role="navigation">
<ul>
<li><a>Menu Item</a></li>
<li>
<a>Menu Item</a>
<ul>
<li><a>Sub Menu Test 1</a></li>
<li>
<a>Sub Menu Test 2</a>
<ul>
<li><a>Sub Menu Test 1</a></li>
<li><a>Sub Menu Test 2</a></li>
<li><a>Sub Menu Test 3</a></li>
</ul>
</li>
<li><a>Sub Menu Test 3</a></li>
</ul>
</li>
<li><a>Menu Item</a></li>
</ul>
</nav>
</div>
<div id="bg">
</div>