【发布时间】:2017-12-07 02:02:14
【问题描述】:
我正在尝试制作一个从标题滑动的下拉菜单。 我有一个标题,里面有一些带有边框底部 1px 线和背景颜色的 div。在这个 div 中,我想放置徽标、搜索框、一些链接和一个用户配置文件按钮。单击此按钮时,我想在此按钮下方下拉菜单。不幸的是,这个下拉菜单出现在标题前面,而不是从标题后面滑动(遮住标题背景和底部边框线)。我已经尝试过如下解决方案(它是简化版)。
header {
position: relative;
z-index: 5;
}
.dropdown {
background-color: yellow;
width: 100px;
height: 100px;
position: absolute;
z-index: 1;
}
.background {
position: absolute;
background-color: #ccca;
border-bottom: 1px solid black;
width: 100%;
height: 50px;
z-index: 2;
}
<header>
<div class="background">
<div class="dropdown">
</div>
</div>
</header>
我尝试了很多 z-index 配置,但似乎都没有。 1. z-index 为 2 的 div.background,z-index 为 1 甚至 -1 的 div.dropdown 2. 没有 z-index 和位置的 div.background,带有 z-index -1 的 div.dropdown(这里的下拉菜单在标题后面,但菜单链接停止工作,菜单也在网页的主要内容后面)
如何使我的 div.dropdown 从带有背景和边框底线的标题栏后面滑动?是否可以在标题 div 树中将此 div.dropdown 作为后代元素。
【问题讨论】: