我已经编写了下面的代码来帮助我理解CSS堆叠顺序但是我被卡住了。 在我将鼠标悬停在链接“Three”(id = link_three)上面的页面中,我希望显示子菜单。 子菜单出现但菜单栏变形,因为子菜单没有堆叠在菜单栏的其余部分上方。这里的堆叠上下文和堆叠顺序是什么?什么是使子菜单出现在上一级的正确方法?
<html>
<head>
<style>
<!--
* {
padding: 0;
border: 0;
margin: 0;
}
.menubar_ul {
list-style: none;
}
.menubar_ul_li,.menubar_ul_li_menu {
float: left;
padding: 0 10px 0 10px;
}
.menu_ul {
list-style: none;
display: none;
}
.menu_ul_li {
}
#link_three:hover>#menu_three {
display: block;
}
-->
</style>
</head>
<body>
<ul id="top_menubar" class="menubar_ul">
<li class="menubar_ul_li" id="link_one">One</li>
<li class="menubar_ul_li" id="link_two">Two</li>
<li class="menubar_ul_li_menu" id="link_three"><a href="#">Three</a>
<ul class="menu_ul" id="menu_three">
<li class="menu_ul_li" id="menuitem_one">One</li>
<li class="menu_ul_li" id="menuitem_two">Two</li>
<li class="menu_ul_li" id="menuitem_three">
<!-- This is intentional: -->
Threeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee</li>
<li class="menu_ul_li" id="menuitem_four">Four</li>
<li class="menu_ul_li" id="menuitem_five">Five</li>
<li class="menu_ul_li" id="menuitem_six">Six</li>
</ul></li>
<li class="menubar_ul_li" id="link_four">Four</li>
<li class="menubar_ul_li" id="link_five">Five</li>
<li class="menubar_ul_li" id="link_six">Six</li>
</ul>
</body>
</html>
答案 0 :(得分:1)
<!-- Just add "position:absolute;" to your css, this is going to be then -->
#link_three:hover>#menu_three {
display: block;
position:absolute;
}