我最初在 Chrome 中创建了我的导航,结果完全符合我的需要。然后我发现 Mozilla Firefox 不会输出相同的结果,Member Action 和 Admin Related 下的下拉菜单将按照我的意愿垂直显示而不是水平显示。然而,我最大的失望是在 Internet Explorer 中测试导航,它甚至不会显示下拉菜单。我非常感谢有人检查以下代码和您的反馈,谢谢。
通过更改 css 中的一行来解决问题;
导航 ul li {浮动:左;列表样式:无;}
HTML
<div id="navigationContainer">
<div id="navigation">
<ul>
<li class="borderleft"><a href="homepage.jsp">Home</a> </li>
<li><a href="Registration.jsp">Register</a> </li>
<li><a href="searchCar.jsp">Search cars</a></li>
<li><a href="DisplayAll.jsp">Display all cars</a></li>
<li><a href="#">Member Actions</a>
<ul> <!-- Open drop down menu -->
<li class="bordertop"><a href="Login.jsp">Login</a></li>
<li class="floatLeft"><a href="Member.jsp">Member Area</a></li>
<li><a href="ReserveCar.jsp">Reservation</a></li>
<li><a href="ContactUs.jsp">Contact us</a></li>
<li><a href="#">Admin Related</a>
<ul>
<li class="bordertop"><a href="braking.html">Insert new car</a></li>
<li><a href="weather.html">Delete a car</a></li>
</ul>
</li>
</ul>
</div>
</div>
</BODY>
</HTML>
CSS
* {padding: 0%; margin 0%; } /* Overwrites the browser stylesheet */
#navigationContainer {background:url(images/navi.png); width:100%;position: relative; white-space:nowrap; word-spacing:0; }
#navigation {width:1200px; height:65px; position: relative; font-family: Arial; margin: 2px auto; font-size: 125%; }
#navigation ul { list-style-type: none; }
#navigation ul li {float: left; position: relative; }
#navigation ul li a { border-right: 2px solid #e9e9e9; padding: 20px;
display: block; margin: 0 auto; text-align: center; color: black; text-decoration: none; }
#navigation ul li a:hover { background: blue; color: white; }
#navigation ul li ul { display: none; }
#navigation ul li:hover ul {display: block; position: absolute; }
#navigation ul li ul li {float:left; position:relative; }
#navigation ul li:hover ul li a { background: #12aeef; color: white; position:relative; margin: 0px auto; border-bottom: 1px solid white; border-right: 1px solid white; width: 119px; }
#navigation ul li:hover ul li a:hover { background: blue;}
.bordertop { border-top: 1px solid white; }
.borderleft { border-left: 2px solid #e9e9e9;}