html - 如何让下拉菜单覆盖其他元素

标签 html css menu position overlay

我正在创建一个小网站,但我无法获得下拉菜单(当我将鼠标悬停在“图库”按钮上时,该菜单会出现)以覆盖菜单下方的段落,而不是将整个内容向下推.我已经尝试了 position: relative; z-index: 9999; 的所有组合.但是,当我设置 position: absolute;对于 <ul>元素它确实有效,但弄乱了 <ul> 的所有布局元素。请帮助我完成这项工作,因为我开始碰到我的头... Here's my code .当您将鼠标悬停在“画廊”按钮上时,您可以看到该段落是如何下降的。我希望段落保持原样并且下拉菜单覆盖它。

最佳答案

首先将父元素定位为relative让它成为establish a new containing block对于绝对定位的后代:

.menu-item {
    width: 33.33%;
    float: left;
    position: relative; /* <-- added declaration */
}

然后,定位嵌套的<ul>绝对,添加 top , left偏移量以及 width :

Example Here

.menu-item ul {
    margin-top: 5px;
    list-style-type: none;
    height: 0px;
    overflow: hidden;

    position: absolute;  /* <-- added declarations */
    left: 0; top: 100%;  /*     here               */
    width: 100%;         /*     and here...        */

    transition: height 1s ease;
}

关于html - 如何让下拉菜单覆盖其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29732488/

相关文章:

javascript - 无法使用 jQuery 显示菜单中的内容文本

html - 菜单字体大小不一样

javascript - 附加到页面的其他部分时,将复选框的值设置为 "checked"

html - 如何编写一个停止/中断无限循环 Rails 应用程序的 Web 按钮?

javascript - Google App Script HTML 表格样式

google-chrome - iPad 2 Chrome 渲染问题

html - 将搜索框表单添加到我的导航栏

android - 如何以编程方式创建 Menu 实例?即在 onCreateOptionsMenu 之外膨胀一个菜单

html - CSS/HTML - 使用 <span> 更改 <p> 的某个部分的位置未按预期工作

css - 灰度背景 Css 图像