当您将鼠标悬停在“治疗”上时,我创建了一个带有下拉功能的菜单。但是,当我申请“职位:固定;”在CSS上的容器类中,下拉菜单不再起作用。菜单进入固定位置,但下拉功能无法在固定位置运行。我想用CSS解决它,有关如何的任何建议?
CustomCell
.container {
overflow: hidden;
background-color: rgba(48, 48, 48, 0.9);
font-family: Helvetica, sans-serif;
width: 100%;
position: fixed;
margin-top: 0;
margin-left: 0;
}
.container a {
float: right;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: right;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
}
.container a:hover,
.dropdown:hover .dropbtn {
background-color: #ff008f;
}
.dropdown-content {
display: none;
position: absolute;
background-color: rgba(255, 255, 255, 0.98);
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f9e9ff;
}
.dropdown:hover .dropdown-content {
display: block;
}
答案 0 :(得分:2)
overflow: hidden
元素上的.container
阻止下拉菜单显示 - 而不是position: fixed
。通过隐藏溢出,您可以防止超出.container
尺寸的元素(例如您的下拉菜单)显示。
.container {
/* overflow: hidden; */
background-color: rgba(48, 48, 48, 0.9);
font-family: Helvetica, sans-serif;
width: 100%;
position: fixed;
margin-top: 0;
margin-left: 0;
}
.container a {
float: right;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: right;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
}
.container a:hover,
.dropdown:hover .dropbtn {
background-color: #ff008f;
}
.dropdown-content {
display: none;
position: absolute;
background-color: rgba(255, 255, 255, 0.98);
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f9e9ff;
}
.dropdown:hover .dropdown-content {
display: block;
}

<div class="stripes">
<div class="container">
<a href="contact-us.html" target="_top">Contact Us</a>
<a href="products-gifts.html" target="_top">Products &
Gifts</a>
<div class="dropdown">
<button class="dropbtn">Treatments</button>
<div class="dropdown-content">
<a href="body-contouring.html" target="_top">Body
Contouring</a>
<a href="cellulite.html" target="_top">Cellulite</a>
<a href="laser-hair-reduction.html" target="_top">Laser Hair Reduction</a>
<a href="laser-peels.html" target="_top">Laser
Peels</a>
<a href="led.html" target="_top">LED</a>
<a href="photofacial.html" target="_top>" Photofacial & Photobody</a>
<a href="spider-veins.html" target="_top">Spider
Veins</a>
</div>
</div>
<a href="home.html" target="_top">Home</a>
</div>
</div>
&#13;