gpt4 book ai didi

html - 创建一个子菜单 html

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

嘿,我对我的下拉菜单进行了相当多的设计,我在添加子菜单时遇到了麻烦,让我们说到下拉菜单 div 上的第一个元素。

我只希望子菜单从定义子菜单悬停的位置开始,然后向右并以与当前子菜单相同的方式下拉。这是我的 html:

    <nav>
<div class="main-nav">
<ul class="left">
<li class="dropdown"><a href="#">Home</a>
<div class="dropdown-content">
<a href="#">Third</a>
<a href="#">Third Link</a>
<a href="#">Third Link 3</a>
</div>
</li>
<li><a href="#">Gods</a></li>
<li><a href="#">Goddesses</a></li>
</ul>
<div class="play-now"></div>
<ul class="right">
<li><a href="#">Heroes</a></li>
<li><a href="#">Myths</a></li>
<li><a href="#">Beasts</a></li>
</ul>
</div>
</nav>

这是全部的CSS:

nav {
padding-left: 5px
}

nav .main-nav {
height: 80px;
width: 100%;
margin-top: 64px;
background: url(../images/navHeader.png) no-repeat top;
position: relative
}

nav .main-nav ul {
width: 360px;
height: 80px;
margin-top: 2px;
padding: 0;
list-style-type: none
}

nav .main-nav ul a,
nav .main-nav ul li {
display: inline-block;
width: 105px;
line-height: 80px;
height: 80px

}

nav .main-nav .dropdown-content a {
height: auto;
line-height: initial;
padding: 3px 0;
}

nav .main-nav ul a {
text-align: center;
font-weight: 550;
font-size: 12px;
color: #84827d;
text-shadow: 1px 1px 1px 1px #000;
text-transform: uppercase;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out
}

nav .main-nav ul a:hover {
text-decoration: none;
color: #7289da
}
nav .main-nav li .dropdown {

}
nav .main-nav .dropdown-content {
position: absolute;
display: none;
float: left;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #3A4FC5;
color: #656161;
opacity: .8;
min-width: 30px;
top: 60px;
}

nav .main-nav .dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: center;
}
nav .main-nav .dropdown-content a:hover {
background-color: #3A4FC5
}

nav .main-nav .dropdown:hover .dropdown-content {
display: inline-block;
}

nav .main-nav ul.left {
float: left;
margin-left: 5px;
}

nav .main-nav ul.right {
float: right;
margin-left: 5px
}

这是片段,

nav {
padding-left: 5px
}

nav .main-nav {
height: 80px;
width: 100%;
margin-top: 64px;
background: url(../images/navHeader.png) no-repeat top;
position: relative
}

nav .main-nav ul {
width: 360px;
height: 80px;
margin-top: 2px;
padding: 0;
list-style-type: none
}

nav .main-nav ul a,
nav .main-nav ul li {
display: inline-block;
width: 105px;
line-height: 80px;
height: 80px

}

nav .main-nav .dropdown-content a {
height: auto;
line-height: initial;
padding: 3px 0;
}

nav .main-nav ul a {
text-align: center;
font-weight: 550;
font-size: 12px;
color: #84827d;
text-shadow: 1px 1px 1px 1px #000;
text-transform: uppercase;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out
}

nav .main-nav ul a:hover {
text-decoration: none;
color: #7289da
}
nav .main-nav li .dropdown {

}
nav .main-nav .dropdown-content {
position: absolute;
display: none;
float: left;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #3A4FC5;
color: #656161;
opacity: .8;
min-width: 30px;
top: 60px;
}

nav .main-nav .dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: center;
}
nav .main-nav .dropdown-content a:hover {
background-color: #3A4FC5
}

nav .main-nav .dropdown:hover .dropdown-content {
display: inline-block;
}

nav .main-nav ul.left {
float: left;
margin-left: 5px;
}

nav .main-nav ul.right {
float: right;
margin-left: 5px
}
<nav>
<div class="main-nav">
<ul class="left">
<li class="dropdown"><a href="#">Home</a>
<div class="dropdown-content">
<a href="#">Third</a>
<a href="#">Third Link</a>
<a href="#">Third Link 3</a>
</div>
</li>
<li><a href="#">Gods</a></li>
<li><a href="#">Goddesses</a></li>
</ul>
<div class="play-now"></div>
<ul class="right">
<li><a href="#">Heroes</a></li>
<li><a href="#">Myths</a></li>
<li><a href="#">Beasts</a></li>
</ul>
</div>
</nav>

最佳答案

$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
<style>
.dropdown-submenu {
position: relative;
}

.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
</style>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Dropdown
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">HTML</a></li>
<li><a tabindex="-1" href="#">CSS</a></li>
<li class="dropdown-submenu">
<a class="test" tabindex="-1" href="#">New dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">2nd level dropdown</a></li>
<li><a tabindex="-1" href="#">2nd level dropdown</a></li>
<li class="dropdown-submenu">
<a class="test" href="#">Another dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">3rd level dropdown</a></li>
<li><a href="#">3rd level dropdown</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</body>
</html>

关于html - 创建一个子菜单 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49994935/

25 4 0