gpt4 book ai didi

css - 下拉菜单大小不正确

转载 作者:行者123 更新时间:2023-11-28 02:00:02 24 4
gpt4 key购买 nike

我有一个包含元素的导航栏,其中两个是下拉菜单。我固定了导航栏上元素的大小,但我无法在下拉的元素上执行此操作。当下拉菜单下降时它太宽了,但是当我将鼠标悬停在元素上时,只有我指定的“固定宽度”的一部分被突出显示,其余的则没有。我希望它们都是 100 像素,并且侧面没有多余的空间,我该怎么做?

代码:

.topnav {
list-style-type: none;
margin: 0 auto;
padding: 0;
overflow: hidden;
background-color: #333;
text-align: center;
align-items: center;
}

.topnav ul {
list-style-type: none;
margin: 0 auto;
}

.topnav li {
float: left;
}

.topnav li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
width: 100px;
}

.topnav li a:hover,
.dropdown:hover .dropbtn {
background-color: #111;
}

li.dropdown {
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}

.topnav .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.topnav .dropdown-content a:hover {
background-color: #f1f1f1;
}

.dropdown:hover .dropdown-content {
display: block;
}
<div class="topnav">
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li class="dropdown"><a href="javascript:void(0)" class="dropbtn">Products</a>
<div class="dropdown-content">
<a href="#">Computers</a>
<a href="#">Tablets</a>
<a href="#">Cell Phones</a>
<a href="#">Wearable Technologies</a>
<a href="#">Accessories</a>
</div>
</li>
<li class="dropdown"><a href="javascript:void(0)" class="dropbtn">Brands</a>
<div class="dropdown-content">
<a href="#">Apple</a>
<a href="#">Samsung</a>
<a href="#">Lenovo</a>
<a href="#">Dell</a>
<a href="#">HP</a>
<a href="#">Sony</a>
<a href="#">Panasonic</a>
<a href="#">Motorola</a>
<a href="#">HTC</a>
</div>
</li>
<li><a href="deals.html">Deals</a></li>
</ul>
</div>

JSFiddle:https://jsfiddle.net/29r9d18a/22/

最佳答案

.dropdown-content CSS 类中删除 min-width: 160px

关于css - 下拉菜单大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49376479/

24 4 0