我想在导航菜单中创建子菜单。我对css知之甚少。 但面临一些问题。 当我在子菜单中添加子菜单。菜单显示为ul li,直接盟友。
#cssmenu {
background: #88BC18;
width: auto;
z-index: 1;
position: relative;
}
#cssmenu ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
zoom: 1;
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0;
margin: 0;
}
#cssmenu.align-right ul li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu ul li a {
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color 25s;
-o-transition: color .25s;
transition: color .25s;
}
#cssmenu ul li a:hover {
color: #004900;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #004900;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width 25s;
-o-transition: width .25s;
transition: width .25s;
}
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #ffffff;
opacity: .5;
}
#cssmenu ul li.last>a:after,
#cssmenu ul li:last-child>a:after {
display: none;
}
#cssmenu ul li.active a {
color: #004900;
}
#cssmenu ul li.active a:before {
width: 100%;
}
#cssmenu.align-right li.last>a:after,
#cssmenu.align-right li:last-child>a:after {
display: block;
}
#cssmenu.align-right li:first-child a:after {
display: none;
}

<div id="navWrap">
<nav class="nav">
<div id="cssmenu" class="centered">
<ul>
<li class='first'><a href="#welcome" class="smoothScroll"><span>Home</span></a></li>
<li><a href="#portfolio" class="smoothScroll"><span>Features</span></a></li>
<li><a href="#services" class="smoothScroll"><span>About</span></a></li>
<li><a href="#prices" class="smoothScroll"><span>Prices</span></a></li>
<li><a href="faq.html" class="smoothScroll"><span>F.A.Q</span></a></li>
<li><a href="how-to-uses.html" class="smoothScroll"><span>How to Use</span></a></li>
<li><a href="#contact" class="smoothScroll"><span>Contact</span></a></li>
<li><a href="#" class="smoothScroll"><span>Log In</span></a></li>
<li class="last"><a href="#" class="smoothScroll"><span>Help</span></a></li>
</ul>
</div>
</nav>
</div>
&#13;
答案 0 :(得分:0)
这应该可以帮助您入门。为子菜单添加了css。
立即查看About
链接。
#cssmenu {
background: #88BC18;
width: auto;
z-index: 1;
position: relative;
}
#cssmenu ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
zoom: 1;
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0;
margin: 0;
}
#cssmenu.align-right ul li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu ul li a {
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color 25s;
-o-transition: color .25s;
transition: color .25s;
}
#cssmenu ul li a:hover {
color: #004900;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #004900;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width 25s;
-o-transition: width .25s;
transition: width .25s;
}
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #ffffff;
opacity: .5;
}
#cssmenu ul li.last>a:after,
#cssmenu ul li:last-child>a:after {
display: none;
}
#cssmenu ul li.active a {
color: #004900;
}
#cssmenu ul li.active a:before {
width: 100%;
}
/* New CSS for Sub Menu */
#cssmenu ul li {
position: relative;
}
#cssmenu ul ul {
position: absolute;
top: 100%;
left: 0;
background: #88BC18;
display: none;
}
#cssmenu ul li:hover ul {
display: block;
}
#cssmenu ul ul li a {
white-space: nowrap;
}
<div id="navWrap">
<nav class="nav">
<div id="cssmenu" class="centered">
<ul>
<li class='first'><a href="#welcome" class="smoothScroll"><span>Home</span></a></li>
<li><a href="#portfolio" class="smoothScroll"><span>Features</span></a></li>
<li><a href="#services" class="smoothScroll"><span>About</span></a>
<ul>
<li><a href="#">Sub Item</a></li>
<li><a href="#">Sub Item</a></li>
<li><a href="#">Sub Item</a></li>
</ul>
</li>
<li><a href="#prices" class="smoothScroll"><span>Prices</span></a></li>
</ul>
</div>
</nav>
答案 1 :(得分:0)
我已添加菜单中的第二项以在其中添加子菜单,并在css底部添加了两个选择器。 Here is the sample
<强> HTML 强>
<div id="navWrap">
<nav class="nav">
<div id="cssmenu" class="centered">
<ul>
<li class='first'><a href="#welcome" class="smoothScroll"><span>Home</span></a></li>
<li><a href="#" class="smoothScroll has_child"><span>Have submenu</span></a>
<ul class="submenu">
<li><a href="#">submenu one</a></li>
<li><a href="#">submenu two</a></li>
</ul>
</li>
<li><a href="#services" class="smoothScroll"><span>About</span></a></li>
<li><a href="#prices" class="smoothScroll"><span>Prices</span></a></li>
<li><a href="faq.html" class="smoothScroll"><span>F.A.Q</span></a>
</li>
<li><a href="how-to-uses.html" class="smoothScroll"><span>How to Use</span></a></li>
<li><a href="#contact" class="smoothScroll"><span>Contact</span></a></li>
<li><a href="#" class="smoothScroll"><span>Log In</span></a></li>
<li class="last"><a href="#" class="smoothScroll"><span>Help</span></a></li>
</ul>
</div>
</nav>
</div>
<强> CSS 强>
#cssmenu {background: #88BC18;width: auto;z-index: 1; position: relative;}
#cssmenu ul {list-style: none; margin: 0; padding: 0; line-height: 1; display: block; zoom: 1; }
#cssmenu ul:after {content: " ";display: block;font-size: 0;height: 0; clear: both;visibility: hidden;}
#cssmenu ul li { display: inline-block;padding: 0;margin: 0;}
#cssmenu.align-right ul li {float: right;}
#cssmenu.align-center ul {text-align: center;}
#cssmenu ul li a {color: #ffffff;text-decoration: none;display: block; padding: 15px 25px;font-family: 'Open Sans', sans-serif;font-weight: 700; text-transform: uppercase;font-size: 14px;position: relative;-webkit-transition: color .25s;-moz-transition: color .25s;-ms-transition: color 25s;-o-transition: color .25s;transition: color .25s;}
#cssmenu ul li a:hover {color: #004900;}
#cssmenu ul li a:hover:before {width: 100%;}
#cssmenu ul li a:before {content: "";display: block;position: absolute; left: 0;bottom: 0; height: 3px;width: 0;background: #004900;-webkit-transition: width .25s;-moz-transition: width .25s;-ms-transition: width 25s; -o-transition: width .25s;transition: width .25s;}
#cssmenu ul li a:after {content: "";display: block;position: absolute; right: -3px; top: 19px;height: 6px; width: 6px;background: #ffffff;opacity: .5;}
#cssmenu ul li.last > a:after,
#cssmenu ul li:last-child > a:after {display: none;}
#cssmenu ul li.active a {color: #004900;}
#cssmenu ul li.active a:before {width: 100%;}
#cssmenu.align-right li.last > a:after,
#cssmenu.align-right li:last-child > a:after {display: block;}
#cssmenu.align-right li:first-child a:after {display: none;}
#cssmenu .submenu{
display:none;
}
#cssmenu li:hover > ul{
display:block;
width:200px;
z-index: 10;
position: absolute;
left: 100px;
top: 44px;
background: #88BC18;
}