gpt4 book ai didi

html - 多级下拉菜单无法在悬停和 Bootstrap 上使用

转载 作者:太空宇宙 更新时间:2023-11-04 06:51:12 24 4
gpt4 key购买 nike

我是 CSS 的新手,正在尝试创建多级下拉菜单。当我点击 Apparel 链接时,它下面的所有内容都会同时打开。我尝试使用 display: none 和 display: block on hover 但是,它不起作用。任何人都可以指导我吗?

ul {
list-style-type: none
}


.navbar-nav:hover .secondDropdown{
display:block;
}


.navbar-nav .secondDropdown{
display:none;
}


.navbarDropdown2{
display:none;
}


.dropdown:hover .navbarDropdown2 {
display: block;
}
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown"><a class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Apparel </a>

<ul class="dropdown-menu secondDropdown" aria-labelledby="navbarDropdown">
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" href="#" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Girls</a>
<ul class="navbarDropdown2" aria-labelledby="navbarDropdown2">
<li class="dropdown-item dropdown"><a href="/Apparel/Girls/Shoes/10015">Shoes</a></li>

</ul>
</li>
<li class="dropdown-item dropdown"><a class="dropdown-toggle" href="#" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Boys</a>
<ul class="navbarDropdown2" aria-labelledby="navbarDropdown2">
<li class="dropdown-item dropdown"><a href="/Apparel/Boys/Pants/10019">Pants</a></li>

</ul>
</li>

</ul>

最佳答案

注意类名,第一个悬停下拉菜单的类名是dropdown-toggle 而不是dropdown

还有代码笔链接 -> https://codepen.io/anon/pen/ReQKJm

ul {
list-style-type: none
}


.navbar-nav:hover .secondDropdown{
display:block;
}


.navbar-nav .secondDropdown{
display:none;
}


.navbarDropdown2{
display:none;
}


.dropdown-toggle:hover .navbarDropdown2 {
display: block;
}

.dropdown-item:hover ul{
display: block;
}
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown"><a class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Apparel </a>

<ul class="dropdown-menu secondDropdown" aria-labelledby="navbarDropdown">
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" href="#" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Girls</a>
<ul class="navbarDropdown2" aria-labelledby="navbarDropdown2">
<li class="dropdown-item dropdown"><a href="/Apparel/Girls/Shoes/10015">Shoes</a></li>

</ul>
</li>
<li class="dropdown-item dropdown"><a class="dropdown-toggle" href="#" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Boys</a>
<ul class="navbarDropdown2" aria-labelledby="navbarDropdown2">
<li class="dropdown-item dropdown"><a href="/Apparel/Boys/Pants/10019">Pants</a></li>

</ul>
</li>

</ul>

希望对你有帮助。

关于html - 多级下拉菜单无法在悬停和 Bootstrap 上使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52850918/

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