我是菜单样式的新手,我很难尝试在现有的下拉菜单中添加子菜单。
CSS如下
.menu_main {
float: left;
width: 60%;
}
#access .menu {
list-style: none;
font-weight: normal;
position: relative;
float: left;
font-family: 'Open Sans', sans-serif;
font-weight: 600;
text-transform: uppercase;
margin-top: 0px;
}
#access .menu select {
border: 2px solid #eee;
padding: 10px 10px 10px 10px;
background-color: #f9f9f9;
color: #333;
}
#access .menu ul {
margin: 0px;
list-style-type: none;
position: relative;
text-align: left;
z-index: 1001;
height: 80px;
margin: 0px 0px 0px 0px;
float: left;
}
#access .menu ul li {
position: relative;
display: inline-block;
padding: 0;
z-index: 101;
margin: 0px 0px 0px 0px;
float: left;
background: url(../images/menu-divider.png) no-repeat right top;
}
#access .menu ul li a {
display: inline-block;
text-decoration: none;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
line-height: 1;
color: #29A9E0;
margin: 0;
padding: 32px 16px 32px 18px;
text-align: center;
}
#access .menu ul li a:hover {
color: #999;
}
#access .menu ul li a.active {
color: #999;
}
#access .menu ul li i {
margin-left: 2px;
}
#access .menu ul li ul {
position: absolute;
left: 0;
height: auto;
display: none;
visibility: hidden;
width: 194px;
padding: 0;
margin-top: -1px;
text-align: left;
background: #615c73;
border-top-left-radius: 0px;
}
#access .menu ul li ul li {
display: list-item;
float: none;
background: none;
padding: 0;
margin: 0;
height: auto;
}
#access .menu ul li ul li ul {
top: 0;
}
#access .menu ul li ul li a {
margin: 0;
border: none;
display: block;
padding: 14px 17px 14px 17px;
font-size: 13px;
font-family: 'Open Sans', sans-serif;
font-weight: normal;
color: #fff;
background: #1B88B8;
width: 159px;
text-align: left;
border-bottom: 1px solid #FFF;
}
#access .menu ul li ul li a:hover,
#access .menu ul li ul li.active a,
#access .menu ul li ul li a.selected {
background: #544e67;
border-bottom: 1px solid #544e67;
color: #fff;
padding: 14px 17px 14px 17px;
}
#access .menu ul li ul li:last-child {
border: none;
}
* html #access .menu {
height: 1%;
}
.selectnav {display: none; width: 440px; margin-left: 20px;}
这是我设计的HTML代码很长一段时间后我正在使用它并且很急,并且无法弄清楚当我向其添加另一个级别时子菜单没有出现。
<div class="menu_main">
<nav id="access" class="access" role="navigation">
<div id="menu" class="menu">
<ul id="tiny">
<li><a href="index.html">Home</a></li>
<li><a href="#">Layouts <i class="fa fa-angle-down"></i></a>
<ul>
<li>
<ul style="top: 600px; visibility: visible; left: 0px; width: 194px; display: block;">
<a href="http://gsrthemes.com/joosa/layout2/fullwidth/index.html">Creative</a>
</ul>
</li>
<li><a href="http://gsrthemes.com/joosa/layout3/fullwidth/index.html">Medical</a></li>
<li><a href="http://gsrthemes.com/joosa/layout4/fullwidth/index.html">Hosting</a></li>
<li><a href="http://gsrthemes.com/joosa/layout5/fullwidth/index.html">One Page</a></li>
<li><a href="http://gsrthemes.com/joosa/layout1/fullwidth/index.html">Corporate</a></li>
</ul>
</li>
<li><a href="#" class="active">Pages <i class="fa fa-angle-down"></i></a>
<ul>
<li><a href="about.html">About Page Style 1</a></li>
<li><a href="about-2.html">About Page Style 2</a></li>
<li><a href="services.html">Services Style 1</a></li>
<li><a href="services-2.html">Services Style 2</a></li>
<li><a href="full-width.html">Full Width Page</a></li>
<li><a href="left-sidebar.html">Left Sidebar Page</a></li>
<li><a href="right-sidebar.html">Right Sidebar Page</a></li>
<li><a href="left-nav.html">Left Navigation</a></li>
<li><a href="right-nav.html">Right Navigation</a></li>
<li><a href="404.html">404 Error Page</a></li>
</ul>
</li>
<li><a href="#">Features <i class="fa fa-angle-down"></i></a>
<ul>
<li><a href="elements.html">Elements</a></li>
<li><a href="typography.html">Typography</a></li>
<li><a href="pricing-tables.html">Pricing Tables</a></li>
<li><a href="columns.html">Page Columns</a></li>
<li><a href="testimonials.html">Testimonials</a></li>
<li><a href="faqs.html">FAQs</a></li>
<li><a href="tabs.html">Tabs</a></li>
<li><a href="#">5 Diffrent Layouts</a></li>
<li><a href="#">Custom BGs & Colors</a></li>
<li><a href="#">PSD Files Included</a></li>
<li><a href="#">Clean & Valid Code</a></li>
<li><a href="#">Useful Typo Elements</a></li>
<li><a href="#">Cross Browser Check</a></li>
</ul>
</li>
<li><a href="#">Portfolio <i class="fa fa-angle-down"></i></a>
<ul>
<li><a href="portfolio-one.html">Single Image</a></li>
<li><a href="portfolio-two.html">2 Columns</a></li>
<li><a href="portfolio-three.html">3 Columns</a></li>
<li><a href="portfolio-four.html">4 Columns</a></li>
<li><a href="portfolio-five.html">Portfolio + Sidebar</a></li>
<li><a href="portfolio-six.html">Portfolio Fancy</a></li>
</ul>
</li>
<li><a href="#">Blog <i class="fa fa-angle-down"></i></a>
<ul>
<li><a href="blog.html">with Large Image</a></li>
<li><a href="blog-2.html">with Small Image</a></li>
<li><a href="blog-post.html">Single Post</a></li>
</ul>
</li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
</nav>
</div>
答案 0 :(得分:1)
当您将父元素悬停时,您必须显示子元素。
#access .menu ul li:hover ul{display:block;}
此外,我注意到您已使用display:none
和visibility:hidden
来隐藏子菜单。这不是必要的。只需使用下面的display:none
。
#access .menu ul li ul {
position: absolute;
left: 0;
height: auto;
display: none;
width: 194px;
padding: 0;
margin-top: -1px;
text-align: left;
background: #615c73;
border-top-left-radius: 0px;
}
答案 1 :(得分:0)
我为你的问题做了一个新的。
我认为this JSFiddle有足够的理论来解决你的问题。
这是关键代码:
ul li:hover ul {
display: block;
}
ul li ul {
margin: 0;
padding:0;
display: none;
position: absolute;
left: 10px;
background:#efefef;
}