我想为我的网站提供一个非常基本的 CSS 下拉菜单。这是代码:
#topNav { font-size: 12px; width: 970px; margin: 0 auto; height: 33px; background: url(images/menubg.png); /*border-bottom: solid 1px #cccccc;*/ }
#topNav ul { margin: 0; padding: 0; list-style: none; margin: 0 auto; }
#topNav ul li { height: 33px; float: left; padding: 0px; font: bold 12px/37px ; }
#topNav ul li a{ padding: 0 18px; height: 33px; float: left; text-decoration: none; display: block; color: #7b7a76; font: 14px/37px Arial, Helvetica, sans-serif; }
#topNav ul li a:hover { padding: 0 18px; height: 33px; /*float: left;*/ text-decoration: underline; display: block; color: #e52128; font: 14px/37px Arial, Helvetica, sans-serif; background: url(images/menuover.png); }
#topNav ul li a:active { padding: 0 18px; height: 33px; /*float: left; text-decoration: none; display: block; color: #666666;*/ font: 14px/37px Arial, Helvetica, sans-serif; background: url(images/menuover.png); }
和 :
.nav, .nav ul { list-style: none; margin: 0; padding: 0; }
.nav { font-family: Arial, Helvetica, sans-serif; z-index: 1000; position: absolute; }
.nav li { float: left; margin: 0; padding: 0; position: relative; /*background: url(images/navbg.jpg) repeat-x 0 0 #292929;*/ }
.nav li a, .nav li a:link, .nav li a:active, .nav li a:visited { font: bold 1.22em/25px Arial, Helvetica, sans-serif; color: #959595; display: block; padding: 0 9px; text-decoration: none; }
.nav li a:hover { background: /*#f2f2f2*/ #FAFBFF; color: #000; }
#nav-one li:hover a, #nav-one li.sfHover a { background: #fff; color: #000; }
#nav-one li:hover ul a, #nav-one li.sfHover ul a { background: #565656; color: #959595; }
#nav-one li:hover ul a:hover, #nav-one li.sfHover ul a:hover { background: #ccc; color: #000; }
.nav ul { background: #565656; /*background: url(images/navbg.jpg) repeat-x 0 0 #292929;*/ list-style: none; margin: 0; width: 150px; position: absolute; top: -999em; left: -1px; }
.nav li:hover ul, .nav li.sfHover ul { top: 37px; }
.nav ul li { border: 0; float: none; }
.nav ul a { border: 1px solid #cccccc; border-bottom: 0; padding-right: 20px; width: 150px; white-space: nowrap; }
.nav ul a:hover { background: #ccc; color: #000; }
下拉菜单显示正常,但是当我将鼠标悬停在下拉项目上时,它消失了。
菜单位于 a 中,如下所示:
<div id="topNav">
<ul class="nav">
我已经尝试将其放入包装器中,但无济于事。