<分区>
<分区>
我正在尝试编辑以下 jQuery 动画菜单,使子文本 div 的宽度绝对为 600px,而不是相对于父菜单列表项的宽度。
我尝试将绝对位置添加到子文本类,但没有成功。
例如,当我将鼠标悬停在“关于”菜单项时,这就是我想要得到的。
非常感谢您的帮助。
最佳答案
以下是一些最重要的样式:
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/