这是我第一次做下拉菜单。我很困惑为什么我的下拉菜单表现得很奇怪。我只是想隐藏子菜单,这样当它悬停时,它就会显示出来。
问题是,当它悬停时,它会将导航分成两半。我不明白。这是一个演示它的jsfiddle,这是我的 HTML 和 CSS 导航代码:
HTML:
<ul id="nav">
<li><a style="background-color:#000000;color:#FFFE41;text-decoration:none;font-weight:bold;" href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="history.html">Camera Phone</a></li>
<li><a href="focus.html">Manual & Auto Focus</a></li>
<li><a href="exposure.html">Exposure</a>
<ul>
<li><a href="iso.html">ISO</a></li>
<li><a href="aperture.html">Aperture</a></li>
<li><a href="shutterspeed.html">Shutter Speed</a></li>
</ul>
</li>
<li><a href="whitebalance.html">White Balance</a></li>
<li><a href="lowlight.html">Low Light</a></li>
<li><a href="epilogue.html">Epilogue</a></li>
</ul>
CSS:
ul#nav {
margin-top: -9px;
/*put nav in the upper-top browser*/
list-style-type: none;
/*gets rid of bullets*/
padding: 0;
text-align:center;
}
#nav li {
margin: 0;
display: inline;
/*display list horizontally*/
margin-left: -4px;
/*dense the links together*/
}
#nav a {
display: inline-block;
/*don't break onto new lines and follow padding accordingly*/
padding:10px;
/*give space between links*/
border-top:1px solid #000000;
border-bottom:1px solid #000000;
}
#nav li > ul {
display:none;
/*hide the sub-nav menus*/
}
#nav li:hover > ul {
/*display sub menus when hovered over*/
display:block;
position:relative;
width:10%;
left:61%;
/*pushes the nav right under where the menu is*/
}