gpt4 book ai didi

html - CSS 堆叠顺序 - 如何做到这一点?

转载 作者:太空宇宙 更新时间:2023-11-04 13:56:43 25 4
gpt4 key购买 nike

我已经编写了下面的代码来帮助我理解 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com