gpt4 book ai didi

html - 如何在下拉菜单中制作下拉菜单?

转载 作者:行者123 更新时间:2023-11-27 23:38:53 25 4
gpt4 key购买 nike

我正在为网站制作下拉菜单。我让第一个部分工作了,但是当我想让一个元素在其右侧显示其他选项时,它就是不工作。

这只是一些基本的 HTML 和 CSS 设置,我只是一个初学者。我尝试整理代码并以尽可能简单的方式进行。

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

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


li.dropdown {
display: inline-block;

}

.dropdown:hover .dropdown-content {
display: 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;

}

.two {
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;
margin-top: -40px;
margin-left: 160px;

}

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


}

.dropdown-content a:hover {

background-color: #f1f1f1;

}
<!-- About section -->
<li class="dropdown">
<a class="dropbtn">About</a>
<div class="dropdown-content">
<a href="mission.html">Mission</a>
<div class="two">
<a href="team.html">Team</a>
</div>

<a href="mission.html">Our Story</a>
<a href="mission.html">Partners</a>
<a href="team.html">Team</a>
</div>
</li>

我想了解我做错了什么,以及我该如何解决这个问题。

最佳答案

在css中使用+号选择子菜单,使其成为display:block。检查以下代码:

.dropdown-content a:hover + div {
display:block;
}

请参阅下面的代码段:

li a, dropbtn {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
background-color:gray;
}

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


li.dropdown {
display: inline-block;

}

.dropdown:hover .dropdown-content {
display: 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;

}

.two {
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;
margin-top: -40px;
margin-left: 160px;

}

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


}

.dropdown-content a:hover {

background-color: #f1f1f1;

}

.dropdown-content a:hover + div {
display:block;
}
<!-- About section -->
<li class="dropdown">
<a class="dropbtn">About</a>
<div class="dropdown-content">
<a href="mission.html">Mission</a>
<div class="two">
<a href="team.html">Team</a>
</div>

<a href="mission.html">Our Story</a>
<a href="mission.html">Partners</a>
<a href="team.html">Team</a>

<div class="two">
<a href="ceo.html">CEO</a>
</div>

</div>
</li>

关于html - 如何在下拉菜单中制作下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57117172/

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