我的悬停似乎不起作用,导航子菜单也是如此,它被认为是一个下拉菜单。因此,对于ul和li元素,它们现在居中,但它们并未在导航菜单中均匀分布 - 它位于底部。
您怎么看?
以下是CSS代码:
nav {
width: 1000px;
background-color: #CCC;
padding: 20px 20px 20px 20px;
margin: 0 auto;
margin-top: 10px;
margin-bottom: 10px;
}
nav ul{
list-style-type: none;
}
nav ul ul{
display: none;
}
nav ul li{
float: left;
}
nav ul a{
color:#666;
text-align: center;
text-decoration: none;
padding: 20px 20px 20px 20px;
font-family: Arial, Helvetica, sans-serif;
}
nav ul a: hover{
color: #FFF;
}
以下是HTML CODES:
<nav>
<ul>
<li><a href="index.html">HOME</a></li>
<li>
<a href="products_and_services.html">PRODUCTS & SERVICES</a>
<ul>
<li><a href="">BROCHURES</a></li>
<li><a href="">BUSINESS CARDS</a></li>
<li><a href="">MAGAZINES</a></li>
<li><a href="">BOOKS</a></li>
<li><a href="">WEB DESIGN</a></li>
</ul>
</li>
<li><a href="gallery.html">GALLERY</a></li>
<li><a href="support.html">SUPPORT</a></li>
<li><a href="contact_us.html">CONTACT US</a></li>
<li><a href="about_us.html">ABOUT US</a></li>
</ul>
</nav>
谢谢,更有力量!
答案 0 :(得分:2)
这是HTML代码:
<nav>
<ul class="nav">
<li><a href="#">home</a></li>
<li><a href="#">about</a>
<ul>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
</ul>
</li>
<li><a href="#">blogs</a>
<ul>
<li><a href="#">item a lonng submenu</a></li>
<li><a href="#">item</a>
<ul>
<li><a href="#">Ray</a></li>
<li><a href="#">Veronica</a></li>
<li><a href="#">Bushy</a></li>
<li><a href="#">Havoc</a></li>
</ul>
</li>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
</ul>
</li>
<li><a href="#">contact</a></li>
<li><a href="#">media</a>
<ul>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
<li><a href="#">item</a></li>
</ul>
</li>
<li><a href="#">here</a></li>
</ul>
</nav>
CSS:
nav {
display: block;
text-align: center;
}
nav ul {
margin: 0;
padding:0;
list-style: none;
}
.nav a {
display:block;
background: #111;
color:#fff;
text-decoration: none;
padding: .8em 1.8em;
text-transform: uppercase;
font-size: 80%;letter-spacing: 2px;
text-shadow: 0 -1px 0 #000;
position: relative;
}
.nav{
vertical-align: top;
display: inline-block;
box-shadow: 1px -1px -1px 1px #000, -1px 1px -1px 1px #fff, 0 0 6px 3px #fff;
border-radius:6px;
}
.nav li{position: relative;}
.nav > li {
float:left;
border-bottom: 4px #aaa solid;
margin-right: 1px;
}
.nav > li > a {
margin-bottom:1px;
box-shadow:inset 0 2em .33em -.5em #555;
}
.nav > li:hover , .nav > li:hover >a{ border-bottom-color:orange;}
.nav li:hover > a { color:orange; }
.nav > li:first-child { border-radius: 4px 0 0 4px;}
.nav > li:first-child>a{border-radius: 4px 0 0 0;}
.nav > li:last-child {
border-radius: 0 0 4px 0;
margin-right: 0;
}
.nav > li:last-child >a{border-radius: 0 4px 0 0; }
.nav li li a { margin-top:1px}
.nav li a:first-child:nth-last-child(2):before {
content:"";
position: absolute;
height:0;
width: 0;
border: 5px solid transparent;
top: 50% ;
right:5px;
}
/* submenu positioning*/
.nav ul {
position: absolute;
white-space: nowrap;
border-bottom: 5px solid orange;
z-index: 1;
left: -99999em;
}
.nav > li:hover > ul {
left: auto;
padding-top: 5px ;
min-width: 100%;
}
.nav > li li ul { border-left:1px solid #fff;}
.nav > li li:hover > ul {
/* margin-left: 1px */
left: 100%;
top: -1px;
}
/* arrow hover styling */
.nav > li > a:first-child:nth-last-child(2):before {
border-top-color: #aaa;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-bottom-color: orange;
margin-top:-5px
}
.nav li li > a:first-child:nth-last-child(2):before {
border-left-color: #aaa;
margin-top: -5px
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-right-color: orange;
right: 10px;
}
答案 1 :(得分:1)
您需要将display block
设置为父li的子菜单
nav ul ul {
display: none;
position:absolute;
width:150px;
}
nav ul a:hover {
color: #FFF;
}
nav ul li:hover ul {
display:block;
}
nav ul li {
display: inline-block;
}
<强> Working demo 强>
答案 2 :(得分:0)
答案 3 :(得分:0)
你必须从a中删除空格:hover使用a:hover然后它将起作用