【发布时间】:2021-05-18 05:53:11
【问题描述】:
我已经困惑了一段时间。我正在制作一个包含多个导航按钮的个人网站,包括一个下拉菜单。当光标悬停在 about 按钮上时,应触发下拉菜单。我使用 W3School 的代码作为基础的一部分。 但是,当我将鼠标悬停在菜单触发的任何按钮上时,我尝试自己创建一个。 我玩弄了使用和使用,但都没有成功。我也尝试创建第二个,但后来我遇到了另一个问题,我无法将按钮(图库和联系人)放在另一个按钮(关于)旁边。下面是 HTML,后面是 CSS。
<nav class="dropdown">
<button class="about" href="about.html">About </button>
<button class="gallery" href="gallery.html">Gallery </a>
<button class="contact" href="contact.html">Contact </a>
<div class="dropdown-content">
<a href="achievements.html">Achievements </a>
<a href="education.html">Education </a>
<a href="hobbies.html">Hobbies </a>
<a href="career.html">Career </a>
</div>
.dropdown{
font-size: 22px;
font-family: "Arvo", serif;
font-weight: bold;
text-align: right;
position:relative;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: relative;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}.dropdown-content a:hover {
background-color: #ddd;
}
.about:hover .dropdown-content {
display: block;
}
.about:hover {background-color: transparent;
}
【问题讨论】: