gpt4 book ai didi

html - 当您尝试选择选项时,CSS 下拉菜单消失

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:15 25 4
gpt4 key购买 nike

一直在尝试做一个下拉菜单;问题是,当试图将鼠标悬停在菜单选项上时,下拉选项会消失 - 但只是有时! (其他时候,没关系!)

代码:

body {
margin: 0;
}

.container {
overflow: hidden;
background-color: rgb(0, 0, 0);
font-family: Arial;
height: 60px;
vertical-align: middle;
}

.container a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 10px 10px;
text-decoration: none;
height: 20px;
vertical-align: middle;
}

.dropdown {
float: left;
overflow: hidden;
}

span {
vertical-align: middle;
}

.dropdown .dropbtn {
font-size: 20px;
border: none;
outline: none;
color: white;
padding: 20px 20px;
background-color: inherit;
}

.redhover a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}

.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;
}

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

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

.dropdown:hover .dropdown-content {
display: block;
}
<div class="container">
<a href="index.html"><img src="homeicon.jpg" width="50" alt="Home"></a>
<div class="redhover">
<div class="dropdown">
<button class="dropbtn">GCSEs</button>
<div class="dropdown-content">
<a href="chemistry.html">Chemistry</a>
<a href="biology.html">Biology</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">A-Levels</button>
<div class="dropdown-content">
<a href="chemistry.html">Chemistry</a>
<a href="biology.html">Biology</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">University</button>
<div class="dropdown-content">
<a href="chemistry.html">Telecommunications</a>
<a href="biology.html">Electronic Engineering</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">More</button>
<div class="dropdown-content">
<a href="biology.html">About me</a>
<a href="https://www.youtube.com/channel/UC5GPvJSUO4599z_ugFuoJwg">Youtube</a>
</div>
</div>
</div>
</div>

有什么想法吗?

非常感谢,瑞安

最佳答案

将 .dropdown .dropbtn 改为 padding: 18px 20px 19px 20px;因为填充大于您的下拉菜单,您将退出悬停区域并且下拉菜单将关闭。请参阅具有较小填充的下拉列表示例,这样您就不会退出悬停区域

body {
margin: 0;
}

.container {
overflow: hidden;
background-color: rgb(0, 0, 0);
font-family: Arial;
height: 60px;
vertical-align: middle;
}

.container a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 10px 10px;
text-decoration: none;
height: 20px;
vertical-align: middle;
}

.dropdown {
float: left;
overflow: hidden;
}

span {
vertical-align: middle;
}

.dropdown .dropbtn {
font-size: 20px;
border: none;
outline: none;
color: white;
padding: 18px 20px 19px 20px;
background-color: inherit;
}

.redhover a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}

.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;
}

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

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

.dropdown:hover .dropdown-content {
display: block;
}
<div class="container">
<a href="index.html"><img src="homeicon.jpg" width="50" alt="Home"></a>
<div class="redhover">
<div class="dropdown">
<button class="dropbtn">GCSEs</button>
<div class="dropdown-content">
<a href="chemistry.html">Chemistry</a>
<a href="biology.html">Biology</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">A-Levels</button>
<div class="dropdown-content">
<a href="chemistry.html">Chemistry</a>
<a href="biology.html">Biology</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">University</button>
<div class="dropdown-content">
<a href="chemistry.html">Telecommunications</a>
<a href="biology.html">Electronic Engineering</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">More</button>
<div class="dropdown-content">
<a href="biology.html">About me</a>
<a href="https://www.youtube.com/channel/UC5GPvJSUO4599z_ugFuoJwg">Youtube</a>
</div>
</div>
</div>
</div>

关于html - 当您尝试选择选项时,CSS 下拉菜单消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44723023/

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