gpt4 book ai didi

html - 下拉菜单不显示子菜单

转载 作者:行者123 更新时间:2023-11-28 16:02:42 27 4
gpt4 key购买 nike

这是我的下拉按钮的代码,其中包含 1 个附加级别。

当我点击按钮时,它工作正常,但是当我尝试在子菜单的下拉菜单中点击时,我意识到出了点问题,我的所有四个元素只显示最后一个子菜单。

.icon-cadet-left {
float: right;
}
.dropbtn {
width: 300px;
background-color: #4CAF50;
color: white;
padding: 16px;
font-family: 'Play';
font-size: 20px;
border: none;
cursor: pointer;
text-transform: uppercase;
letter-spacing: 2px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
width: 300px;
color: black;
font-family: 'Play';
letter-spacing: 2px;
padding: 12px 16px;
text-decoration: none !important;
display: block;
text-align: center;
border-bottom: 0.1em solid #e1e1e1;
border-radius: 5%;
text-transform: uppercase;
overflow: hidden;
}
#dropdown-submenu {
display: none;
background-color: #f9f9f9;
position: absolute;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
left: 100%;
top: 0px;
}
#dropdown-submenu a {
z-index: 1000;
width: 300px;
color: black;
font-family: 'Play';
letter-spacing: 2px;
padding: 12px 16px;
text-decoration: none !important;
display: block;
text-align: center;
border-bottom: 0.1em solid #e1e1e1;
border-radius: 5%;
text-transform: uppercase;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
#dropdown-submenu a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content:hover #dropdown-submenu {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<div class="pricing-button">
<div class="dropdown">
<button class="dropbtn">Logo Design</button>
<div class="dropdown-content animated fadeIn">
<a class="span1" href="#">Logo & Identity<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div id="dropdown-submenu">
<a>Logo Design</a>
<a>Business Cards</a>
<a>Sationary</a>
<a>Holiday Doodles</a>
</div>
<a class="hover2" href="#">Business & Advertising<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div id="dropdown-submenu">
<a>Sample 01</a>
<a>Sample 02</a>
<a>Sample 03</a>
<a>Sample 04</a>
</div>
<a class="hover3" href="#">Website & Digitals<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div id="dropdown-submenu">
<a>Sample 01</a>
<a>Sample 02</a>
<a>Sample 03</a>
<a>Sample 04</a>
</div>
<a class="hover4" href="#">Textile Designing<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div id="dropdown-submenu">
<a>Sample 01</a>
<a>Sample 02</a>
<a>Sample 03</a>
<a>Sample 04</a>
</div>
</div>
</div>
</div>

最佳答案

这就是我在您的代码中所做的更改:

  1. 您的语法无效 - 您不能有多个 id - 为此请使用 class

    所以我将 dropdown-submenu 更改为 class

  2. 而不是 .dropdown-content:hover #dropdown-submenu 使用这个:

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

    相邻的兄弟选择器 (+) 选择紧跟在菜单 a 标记之后的 dropdown-submenu

Adjacent sibling selector (+) that selects the sibling element that immediately follows. See here and here for examples.

让我知道您对此的反馈。谢谢!

.icon-cadet-left {
float: right;
}
.dropbtn {
width: 300px;
background-color: #4CAF50;
color: white;
padding: 16px;
font-family: 'Play';
font-size: 20px;
border: none;
cursor: pointer;
text-transform: uppercase;
letter-spacing: 2px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
width: 300px;
color: black;
font-family: 'Play';
letter-spacing: 2px;
padding: 12px 16px;
text-decoration: none !important;
display: block;
text-align: center;
border-bottom: 0.1em solid #e1e1e1;
border-radius: 5%;
text-transform: uppercase;
overflow: hidden;
}
.dropdown-submenu {
display: none;
background-color: #f9f9f9;
position: absolute;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
left: 100%;
top: 0px;
}
.dropdown-submenu a {
z-index: 1000;
width: 300px;
color: black;
font-family: 'Play';
letter-spacing: 2px;
padding: 12px 16px;
text-decoration: none !important;
display: block;
text-align: center;
border-bottom: 0.1em solid #e1e1e1;
border-radius: 5%;
text-transform: uppercase;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown-submenu a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content a:hover + .dropdown-submenu {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<div class="pricing-button">
<div class="dropdown">
<button class="dropbtn">Logo Design</button>
<div class="dropdown-content animated fadeIn">
<a class="span1" href="#">Logo & Identity<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div class="dropdown-submenu">
<a>Logo Design</a>
<a>Business Cards</a>
<a>Sationary</a>
<a>Holiday Doodles</a>
</div>
<a class="hover2" href="#">Business & Advertising<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div class="dropdown-submenu">
<a>Sample 01</a>
<a>Sample 02</a>
<a>Sample 03</a>
<a>Sample 04</a>
</div>
<a class="hover3" href="#">Website & Digitals<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div class="dropdown-submenu">
<a>Sample 01</a>
<a>Sample 02</a>
<a>Sample 03</a>
<a>Sample 04</a>
</div>
<a class="hover4" href="#">Textile Designing<i class="fa fa-caret-right icon-cadet-left"></i></a>
<div class="dropdown-submenu">
<a>Sample 01</a>
<a>Sample 02</a>
<a>Sample 03</a>
<a>Sample 04</a>
</div>
</div>
</div>
</div>

关于html - 下拉菜单不显示子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39803054/

27 4 0