所以我试图创建一个带有下拉子菜单的侧边栏,这已经过了三天,我仍然无法告诉我在下拉菜单中出现的故障。有人可以如此友好地纠正我的代码吗? (对不起,它很乱。我的大脑目前就像那个大气。)
问题是我想在侧边栏中创建下拉菜单,但下拉子菜单不会丢失。它只是给出了一个列表而不是下拉列表。请参阅下面的this fiddle或摘录。
#wrapper {
padding-left: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#wrapper.toggled {
padding-left: 250px;
}
#sidebar-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 0;
height: 100%;
margin-left: -250px;
overflow-y: auto;
overflow-x:hidden;
background: #000;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#wrapper.toggled #sidebar-wrapper {
width: 250px;
}
#page-content-wrapper {
width: 100%;
padding: 15px;
}
#wrapper.toggled #page-content-wrapper {
position: absolute;
margin-right: -250px;
}
/* Sidebar Styles */
.sidebar-nav {
position: absolute;
top: 0;
width: 250px;
margin: 0;
padding: 0;
list-style: none;
}
.sidebar-nav li {
text-indent: 20px;
line-height: 40px;
}
.sidebar-nav li a {
display: block;
text-decoration: none;
color: #999999;
}
.sidebar-nav li a:hover {
text-decoration: none;
color: #fff;
background: rgba(255,255,255,0.2);
}
.sidebar-nav li a:active,
.sidebar-nav li a:focus {
text-decoration: none;
}
.sidebar-nav > .sidebar-brand {
height: 65px;
font-size: 18px;
line-height: 60px;
}
.sidebar-nav > .sidebar-brand a {
color: #999999;
}
.sidebar-nav > .sidebar-brand a:hover {
color: #fff;
background: none;
}
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a {
margin: 0;
padding: 0;
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#cssmenu {
width: 200px;
font-family: Helvetica, Arial, sans-serif;
color: #ffffff;
}
#cssmenu ul ul {
display: none;
}
.align-right {
float: right;
}
#cssmenu > ul > li > a {
padding: 15px 20px;
border-left: 1px solid #49505a;
border-right: 1px solid #49505a;
border-top: 1px solid #49505a;
cursor: pointer;
z-index: 2;
font-size: 14px;
font-weight: bold;
text-decoration: none;
color: #ffffff;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
background: #49505a;
background: -webkit-linear-gradient(#49505a, #32373e);
background: -moz-linear-gradient(#49505a, #32373e);
background: -o-linear-gradient(#49505a, #32373e);
background: -ms-linear-gradient(#49505a, #32373e);
background: linear-gradient(#49505a, #32373e);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
#cssmenu > ul > li > a:hover,
#cssmenu > ul > li.active > a,
#cssmenu > ul > li.open > a {
color: #49505a;
background: #424852;
background: -webkit-linear-gradient(#32373e, #1992d1);
background: -moz-linear-gradient(#32373e, #1992d1);
background: -o-linear-gradient(#32373e, #1992d1);
background: -ms-linear-gradient(#32373e, #1992d1);
background: linear-gradient(#32373e, #1992d1);
}
#cssmenu > ul > li.open > a {
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.15);
border-bottom: 1px solid #49505a;
}
#cssmenu > ul > li:last-child > a,
#cssmenu > ul > li.last > a {
border-bottom: 1px solid #49505a;
}
.holder {
width: 0;
height: 0;
position: absolute;
top: 0;
right: 0;
}
.holder::after,
.holder::before {
display: block;
position: absolute;
content: "";
width: 6px;
height: 6px;
right: 20px;
z-index: 10;
-webkit-transform: rotate(-135deg);
-moz-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
-o-transform: rotate(-135deg);
transform: rotate(-135deg);
}
.holder::after {
top: 17px;
border-top: 2px solid #ffffff;
border-left: 2px solid #ffffff;
}
#cssmenu > ul > li > a:hover > span::after,
#cssmenu > ul > li.active > a > span::after,
#cssmenu > ul > li.open > a > span::after {
border-color: #eeeeee;
}
.holder::before {
top: 18px;
border-top: 2px solid;
border-left: 2px solid;
border-top-color: inherit;
border-left-color: inherit;
}
#cssmenu ul ul li a {
cursor: pointer;
border-bottom: 1px solid #32373e;
border-left: 1px solid #32373e;
border-right: 1px solid #32373e;
padding: 10px 20px;
z-index: 1;
text-decoration: none;
font-size: 13px;
color: #eeeeee;
background: #49505a;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
#cssmenu ul ul li:hover > a,
#cssmenu ul ul li.open > a,
#cssmenu ul ul li.active > a {
background: #424852;
color: #ffffff;
}
#cssmenu ul ul li:first-child > a {
box-shadow: none;
}
#cssmenu ul ul ul li:first-child > a {
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
#cssmenu ul ul ul li a {
padding-left: 30px;
}
#cssmenu > ul > li > ul > li:last-child > a,
#cssmenu > ul > li > ul > li.last > a {
border-bottom: 0;
}
#cssmenu > ul > li > ul > li.open:last-child > a,
#cssmenu > ul > li > ul > li.last.open > a {
border-bottom: 1px solid #32373e;
}
#cssmenu > ul > li > ul > li.open:last-child > ul > li:last-child > a {
border-bottom: 0;
}
#wrapper > #sidebar-wrapper > .sidebar-nav > b#cssmenu ul ul li.has-sub > a::after {
display: block;
position: absolute;
content: "";
width: 5px;
height: 5px;
right: 20px;
z-index: 10;
top: 11.5px;
border-top: 2px solid #eeeeee;
border-left: 2px solid #eeeeee;
-webkit-transform: rotate(-135deg);
-moz-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
-o-transform: rotate(-135deg);
transform: rotate(-135deg);
}
#cssmenu ul ul li.active > a::after,
#cssmenu ul ul li.open > a::after,
#cssmenu ul ul li > a:hover::after {
border-color: #ffffff;
}
@media(min-width:768px) {
#wrapper {
padding-left: 186px;
}
#wrapper.toggled {
padding-left: 0;
}
#sidebar-wrapper {
width: 161px;
}
#wrapper.toggled #sidebar-wrapper {
width: 0;
}
#page-content-wrapper {
padding: 20px;
}
#wrapper.toggled #page-content-wrapper {
position: relative;
margin-right: 0;
}
}

<body>
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand"><a href="#">Lyfe Craft</a></li>
<li><a href="#">Intro</a></li>
<div id='cssmenu'>
<ul>
<li class='active has-sub'><a href='#'><span>Gliders</span></a>
<ul>
<li class='has-sub'><a href='#'><span>Glider 1</span></a></li>
<li class='has-sub'><a href='#'><span>Glider 2</span></a></li>
<li class='has-sub'><a href='#'><span>Glider 3</span></a></li>
<li class='has-sub'><a href='#'><span>Glider 4</span></a></li>
<li class='has-sub'><a href='#'><span>Glider 5</span></a></li>
<li class='has-sub'><a href='#'><span>Glider 6</span></a></li>
</ul>
</li>
<li class='active has-sub'><a href='#'><span>Cycles</span></a>
<ul>
<li class='has-sub'><a href='#'><span>Cycle 1 (12)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 2 (12)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 3 (24)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 4 (36)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 5 (42)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 6 (60)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 7 (84)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 8 (144)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 9 (582)</span></a></li>
<li class='has-sub'><a href='#'><span>Cycle 10 (3966)</span></a></li>
</ul>
</li>
</ul>
</div>
<li><a href="#">Boomerang</a></li>
<li><a href="#">Deflect (Routing)</a></li>
<li><a href="#">Logic (Interaction Gate)</a></li>
<li><a href="#">Move</a></li>
<li><a href="#">Fast and Slow</a></li>
<li><a href="#">Capture and Emit</a></li>
<li><a href="#">Delayed Release</a></li>
<li><a href="#">Attraction</a></li>
<li><a href="#">Order Out of Chaos</a></li>
<li><a href="#">Structure and Decay</a></li>
<li><a href="#">Big Bang (Entropy)</a></li>
<li><a href="#">Strung Out</a></li>
<li><a href="#">Octave</a></li>
<li><a href="#">Harmonic Chaos</a></li>
</ul>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="topbar">
<div id="topbarcontent">
<!-- </p><button class="bannerButtons" onclick="toggleRunning()">RUN/STOP</button>
<button class="bannerButtons" onclick="fastSlow()">FAST/SLOW</button>
<button class="bannerButtons" onclick="isRunning = true; mainLoop(); isRunning = false;">STEP</button>
<button class="bannerButtons" onclick="reverseDirection()">DIRECTION</button>
<button class="bannerButtons" onclick="randomCells(12, -2, 1)">RANDOM</button>
<button class="bannerButtons" onclick="playStopMusic()">MUSIC</button>
<button class="bannerButtons" onclick="toggleTrails()">TRAILS</button>
<button class="bannerButtons" onclick="clearGrid()">CLEAR</button>
<button class="bannerButtons" onclick="update()">UPDATE</button> -->
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Run/Stop</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Fast/Slow</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Step</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Direction </button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Random</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Music</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Trials</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i>Clear</button>
<button class="btn btn-inverse active"><i class="icon-music icon-white"></i> Update</button>
<div id="banner">
<!-- <span style="background-color: #fff; opacity:0.5; border-bottom: 1px solid #ddd; padding: 8px 10px; font-size:medium"> -->
<b>click & drag to rotate view | scroll to zoom | arrows move cursor; U & D for up/down | ENTER to create/delete | S to step</b>
</span>
<a href="faq.html" target="_blank" style="font-size:larger">faq</a>
<a href="https://github.com/danx0r/BusyBoxes" target="_blank" style="font-size:larger">source</a>
</div>
</div>
</div>
</div>
<!-- <h1>Simple Sidebar</h1>
<p>This template has a responsive menu toggling system. The menu will appear collapsed on smaller screens, and will appear non-collapsed on larger screens. When toggled using the button below, the menu will appear/disappear. On small screens, the page content will be pushed off canvas.</p>
<p>Make sure to keep all page content within the <code>#page-content-wrapper</code>.</p> -->
<a href="#menu-toggle" class="slider btn btn-default" id="menu-toggle">Toggle Menu</a>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
</script>
</body>
</html>
&#13;
答案 0 :(得分:1)
我在你的CSS底部做了一些编辑:
(我不想重写所有的CSS,因为那里有很多东西)
/* New Edits */
#cssmenu {
display: none;
}
ul > li:hover > #cssmenu {
display: block;
}
#cssmenu > ul > .has-sub:hover > ul {
display: block;
}
但我真的认为你应该从一开始就开始,也许会经历一些教程。你的标记中也有一些问题(我需要将整个#cssmenu div包装在列表项中才能使其正常工作),所以经过一些调整之后它似乎正常工作,而这里是小提琴 - http://jsfiddle.net/ym12ddjh/2/
希望这能缓解你3天的痛苦:)
答案 1 :(得分:0)
您可以使用<ul> <li>
创建菜单。在<li>
中创建下拉菜单并隐藏。在悬停父菜单时显示下拉列表。
找到下面的example
<强> HTML 强>
<div class="wrapper">
<aside>
<ul class="sidemenu">
<li><a href="#">Menu 1</a></li>
<li>
<a href="#">Menu 2</a>
<ul>
<li><a href="#">Subenu 1</a>
<ul>
<li><a href="#">Subenu 1</a></li>
<li><a href="#">Subenu 2</a></li>
</ul>
</li>
<li><a href="#">Subenu 2</a></li>
</ul>
</li>
<li><a href="#">Menu 3</a></li>
<li><a href="#">Menu 4</a></li>
</ul>
</aside>
<div class="content">
Main content
</div>
<div>
<强> CSS 强>
*{
font-family: arial;
font-size: 12px;
}
.wrapper{
overflow: hidden;
background: #eee;
}
aside{
float: left;
width: 30%;
background: #ddd;
}
.content{
float:left;
width: 70%;
}
ul.sidemenu{
padding:0;
margin:0;
}
.sidemenu li{
list-style:none;
}
.sidemenu li a{
padding: 10px;
display:block;
color:#000;
border-bottom: 1px solid #fff;
}
.sidemenu li li a{
background: #999;
}
.sidemenu li ul{
display:none;
}
.sidemenu li:hover >ul{
display:block;
}