jQuery 动画菜单下拉菜单占据容器的整个宽度

标签 jquery css drop-down-menu jquery-animate

<分区>

我正在尝试编辑以下 jQuery 动画菜单,使子文本 div 的宽度绝对为 600px,而不是相对于父菜单列表项的宽度。

Click here for the code

我尝试将绝对位置添加到子文本类,但没有成功。

例如,当我将鼠标悬停在“关于”菜单项时,这就是我想要得到的。

enter image description here

非常感谢您的帮助。

最佳答案

以下是一些最重要的样式:

ul {
    list-style: none;     /* Get rid of bullets on li tags */
    position: relative;   /* Use relative position here, but not on li tags */
}
li {
    /* position: relative; */   /* Remove this style, to make all dropdown
                                   divs appear at the same location */
}
a {
    outline: none;   /* Get rid of outline on links */
}
.subtext {
    overflow: hidden;
    height: 0;
    position: absolute;
    z-index: 1;
}
li:hover .subtext {
    z-index: 2;   /* Make sure the active menu dropdown is on top */
}
/* Apply background color to both the li tags and the dropdown divs */
.green,  .green  .subtext { background-color: #6AA63B; }
.yellow, .yellow .subtext { background-color: #FBC700; }
.red,    .red    .subtext { background-color: #D52100; }
.purple, .purple .subtext { background-color: #5122B4; }
.blue,   .blue   .subtext { background-color: #0292C0; }

带有 CSS 过渡的版本添加了以下样式:

.subtext {
    -webkit-transition: height 0.6s;
       -moz-transition: height 0.6s;
            transition: height 0.6s;
}
li:hover .subtext {
    height: 200px;
}

两个演示使用相同的 HTML 和大部分相同的 CSS。这两个版本都不需要编辑现有的 HTML。带有 CSS 转换的版本不需要 jQuery。

关于jQuery 动画菜单下拉菜单占据容器的整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15601192/

上一篇:css - 编译后登录表单出现奇怪的边框

下一篇:css - codeigniter 的分页 CSS 不起作用

相关文章:

jquery - Kendo 更改网格中的字体颜色

javascript - 如何在 swiper.js 中更改 swiper 幻灯片轮播?

javascript - .css 函数的回调

javascript - 带有 3 级深度 jquery 下拉菜单的对 Angular 线鼠标悬停

c++ - 在 Win32 API 中禁用组合框项

javascript - 脚本有时会延迟页面加载,我该如何测试/解决?

javascript - 如何在javascript中用单引号存储数组?是否可以

javascript - 如何将每个 div 背景设置为其内部 HTML

javascript - 在响应模板上调整 Eventbrite 票证表单 iframe 的大小

jquery - 使用 jQuery 使选择下拉菜单成为必需