gpt4 book ai didi

javascript - 像图片中那样在css中制作下拉菜单

转载 作者:太空宇宙 更新时间:2023-11-04 09:11:28 25 4
gpt4 key购买 nike

我对如何重现以下内容有疑问:

enter image description here

我有这样的菜单:

body {
background: white;
margin: 0;
padding: 0;
}
/*
/ nav
*/

nav {
width: 100%;
background: #000;
border-bottom: 5px solid white;
position: relative;
font-family: 'Decker';
}
nav:after {
content: '';
height: 8px;
width: 100%;
background: inherit;
position: absolute;
bottom: -15px;
left: 0px;
z-index: 1;
}
nav ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
max-width: 100%;
margin: auto;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding-bottom: .6em;
}
nav li {
display: inline-block;
list-style: none;
position: relative;
padding: 0 .5em;
}
nav li:last-child a:before {
display: none;
}
nav li a {
color: #fff;
display: inline-block;
padding: 1.6em 0.6em 0.7em 0.6em;
text-decoration: none;
position: relative;
font-size: 18px;
line-height: 1;
}
nav li a:before {
content: "|";
display: block;
position: absolute;
right: -10px;
top: 1.6em;
-webkit-transform: translateY(-4%);
transform: translateY(-4%);
line-height: inherit;
font-size: inherit;
color: #fff;
}
nav li a:after {
display: none;
content: "";
position: absolute;
bottom: -25px;
left: 0px;
width: 100%;
height: 8px;
background: #fac312;
z-index: 2;
}
nav li a:hover {
background: #b42024;
color: #fff;
text-decoration: none;
}
nav li a.active {
background: #b42024;
color: #fff;
text-decoration: none;
}
nav li a.active:after {
display: block;
content: "";
position: absolute;
bottom: -25px;
left: 0px;
width: 100%;
height: 8px;
background: #fac312;
z-index: 2;
}
nav li a:hover:after {
display: block;
}
<nav>
<ul>
<li>
<a href="" class="active">Home</a>
</li>
<li>
<a href="">About Us</a>
</li>
<li>
<a href="">Products</a>
</li>
<li>
<a href="">Contact</a>
</li>
</ul>
</nav>

但是,我不知道如何制作如上图所示的下拉列表。

我希望有人能帮助我。提前致谢!

最佳答案

嘿,这就是你想要的 :) 我希望

body {
background: white;
margin: 0;
padding: 0;
}

nav {
width: 100%;
background: #000;
border-bottom: 5px solid white;
position: relative;
}
nav:after {
content: '';
height: 8px;
width: 100%;
background: inherit;
position: absolute;
bottom: -15px;
left: 0px;
z-index: 1;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
nav a {
color: #fff;
text-decoration: none;
}

.nav__cat {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
max-width: 100%;
margin: auto;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding-bottom: .6em;
}

.nav__li {
display: inline-block;
list-style: none;
position: relative;
padding: 0 .5em;
}
.nav__li:last-child a:before {
display: none;
}
.nav__li:hover > a {
background: red;
}
.nav__li:hover > a:after {
display: block;
}
.nav__li:hover .sub__category {
visibility: visible;
opacity: 1;
}

.nav__li > a {
display: inline-block;
padding: 25.6px 0.6em 0.7em 0.6em;
position: relative;
font-size: 18px;
line-height: 1;
}
.nav__li > a:before {
content: "|";
display: block;
position: absolute;
right: -10px;
top: 25.6px;
-webkit-transform: translateY(-4%);
transform: translateY(-4%);
line-height: inherit;
font-size: inherit;
}
.nav__li > a:after {
display: none;
content: "";
position: absolute;
bottom: -25px;
left: 0px;
width: 100%;
height: 8px;
background: #ffaf1a;
z-index: 2;
}

.sub__category {
visibility: hidden;
opacity: 0;
}

.sub__category {
position: absolute;
top: 100%;
left: 0px;
min-width: 160px;
width: 100%;
z-index: 3;
margin: 0 .5em;
padding-top: 25.6px;
-webkit-transition: all .12s linear;
transition: all .12s linear;
}

.sub__li {
text-align: center;
border-bottom: 2px #000 solid;
background: red;
}

.sub__link {
padding: .7em 1em;
display: block;
font-size: 14px;
}
.sub__link:hover {
background: #fff;
color: #000;
}
<nav>
<ul class="nav__cat">
<li class="nav__li"><a href="">Menu 1</a></li>
<li class="nav__li"><a href="">Menu 23</a>
<ul class="sub__category">
<li class="sub__li">
<a href="#" class="sub__link">Subcategory</a>
</li>
<li class="sub__li">
<a href="#" class="sub__link">Subcategory 2 </a>
</li>
<li class="sub__li">
<a href="#" class="sub__link">Subcategory 3 </a>
</li>
</ul>
</li>
<li class="nav__li"><a href="">Menu 345</a>
<ul class="sub__category">
<li class="sub__li">
<a href="#" class="sub__link">Subcategory</a>
</li>
<li class="sub__li">
<a href="#" class="sub__link">Subcategory 2 </a>
</li>
<li class="sub__li">
<a href="#" class="sub__link">Subcategory 3 </a>
</li>
</ul>
</li>
<li class="nav__li"><a href="">Menu 4567</a></li>
<li class="nav__li"><a href="">Menu 56789</a></li>
</ul>
</nav>

关于javascript - 像图片中那样在css中制作下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42092721/

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