我已经编写了以下代码来帮助我了解CSS堆叠顺序,但是我被卡住了。
当我将鼠标悬停在链接“三”(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>
最佳答案
<!-- Just add "position:absolute;" to your css, this is going to be then -->
#link_three:hover>#menu_three {
display: block;
position:absolute;
}
关于html - CSS堆叠顺序-如何正确处理?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21808249/