gpt4 book ai didi

javascript - 下拉,适应 parent 的宽度?

转载 作者:行者123 更新时间:2023-11-28 10:21:39 29 4
gpt4 key购买 nike

所以我试图让我的下拉菜单正常工作。下拉列表位于我的标题中的列表项下,该列表项会根据用户的用户名而变化。这使得大小不同,但我无法让下拉菜单跟随宽度调整大小。

示例 1: http://jsfiddle.net/73tUx/

这里它是否正常工作,但是如果......

示例 2: http://jsfiddle.net/73tUx/1/

正如您在示例 2 中看到的,下拉列表比列表项更宽。我怎样才能让它也改变宽度?

CSS:

header {
height: 72px;
width: 100%;
z-index: 999;
position: relative;
background-color: #2C3E50;
}

header ul {
margin: 0;
padding: 0;
list-style-type: none;
width: 600px;
height: 72px;
margin-left: auto;
margin-right: auto;
}

.navItem {
float: left;
padding-left: 35px;
padding-right: 35px;
padding-top: 26px;
padding-bottom: 26px;
text-decoration: none;
color: #FFF;
}

.navItem:hover {
background-color: #34495e;
}

header ul li a.right {
float: right;
}

.dropdown {
list-style-type: none;
}

.drop {
position: absolute;
float: right;
background: #2C3E50;
margin-top: 72px;
right: 103px;
width: 150px;
height: 140px;
display: none;
z-index: -10;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;

}

.drop li {
list-style-type: none;
height: 25px;
padding-top: 10px;
padding-left: 20px;
width: 123px;
}

.drop li a {
color: #FFF;
text-decoration: none;
}

.drop li:hover {
background: #34495e;
}

最佳答案

header ul{width:100%;position:relative;}

关于javascript - 下拉,适应 parent 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23969081/

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