我可能在这里做错了。这是我的代码:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: auto;
background-color: #000066;
z-index: 1;
}
.header {
position: fixed;
top: 0;
width: 100%;
overflow: auto;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .droptn {
background-color: #ccb3ff;
color: black;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #ccb3ff;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 2;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block, flex;
flex-flow: column;
justify-content: space-evenly;
flex-grow: 2;
text-align: left;
z-index: 3;
}
.dropdown-content a:hover {background-color: white; color: #000066;}
.dropdown:hover .dropdown-content {display: block;}
<ul class="header">
<li><a href="#home">Home</a></li>
<li><a href="#about">About Us</a></li>
<li><a href="#quote">Request a Quote</a></li>
<li><a href="#colors">Colors</a></li>
<li class="dropdown"><a href="javascript:void(0)" class="dropbtn">Products</a>
<div class="dropdown-content">
<a href="#addressblocks">Address Blocks</a>
<a href="#balls">Balls and Finials</a>
<a href="#columns">Columns</a>
<a href="#coping">Coping (Wall Caps)</a>
<a href="#custom">Custom Products</a>
<a href="#fireplaces">Fireplaces</a>
<a href="#edgers">Lawn Edgers and Tree Rings</a>
<a href="#panels">Panel System</a>
<a href="#patiostones">Patio Stones and Pavers</a>
<a href="#parkingbumpers">Parking Bumpers</a>
<a href="#pierandtiercaps">Pier (Pillar) and Tier Caps</a>
<a href="#quoins">Quoins</a>
<a href="#sillsandlintels">Sills and Lintels</a>
<a href="#splashblocks">Splash Blocks</a>
<a href="#surrounds">Window and Door Trim (Surrounds)</a>
<a href="#wainscots">Wainscots</a>
</div>
</li>
</ul>
显示我的下拉菜单时,它会显示在标题中,并带有一个很小的滚动条,并且不会从标题中下拉出来。我知道我可能是个白痴,这很容易解决。 A picture of what I'm talking about.我显然尝试过弄乱元素的z-indexs。它什么也没做。我已经用Google搜寻了我的小指,并且一直在尝试尝试。什么都没用。我是个假人。
答案 0 :(得分:1)
您遇到的问题是,溢出被设置为自动,因此当悬停在下拉列表上并且大于分配的空间时,会导致滚动条出现。要解决此问题,请从标题和ul中删除overflow:auto
。
有关工作示例,请参见此小提琴。