CSS下拉菜单在IE中定位问题
我编写了一个 css 下拉菜单,它似乎在除 Internet Explorer 之外的每个浏览器中都能正常工作(至少在 IE7 中)。
这是一个图片链接,展示了它在正确运行时的外观(还没有足够的代表来发布图片): http://img535imageshack.us/i/chromeexample.png/
下面是它在 IE 中的外观的链接: http://img299.imageshack.us/i/ieexample.png/
如果您想查看整个网站,请访问urbanpromise.org
这是CSS 菜单编码:
.menu{
width: 40em;
height: 2em;
background: #63089C;
float: left;
font-family: helvetica, arial, sans-serif;
}
.menu ul{
list-style: none;
float: left;
padding: .4em .75em;
margin: 0;
text-align: center;
font-weight: bold;
color: white;
}
.menu a{
text-decoration: none;
color: white;
}
.menu ul:hover{
color: black;
background: white;
}
.menu a:hover{
color: black;
background: white;
}
.menu ul ul{
position: absolute;
z-index: 500;
text-align: left;
}
div.menu ul ul{
display: none;
font-weight: normal;
}
div.menu ul li:hover ul{
display: block;
background: #63089C;
border: 0px solid black;
border-width: .125em 0;
}
提前感谢您的帮助。
编辑:这是菜单的 HTML 代码:
<div class="menu">
<ul>
<li><a href="index.php?go=home"><span class="h2">Home</span></a></li>
</ul>
<ul>
<li>Information <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=staffandboard">Staff and Board</a></li>
<li><a href="index.php?go=historyandmission">History and Mission</a></li>
<li><a href="index.php?go=media">Media</a></li>
<!--<li><a href="index.php?go=speakerinfo">Speaker Information</a></li>-->
<li><a href="index.php?go=contactus">Contact Us</a></li>
</ul>
</li>
</ul>
<ul>
<li>Calendars <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=schoolcalendar">UrbanPromise School</a></li>
<li><a href="index.php?go=programcalendar">Summer/Afterschool</a></li>
<li><a href="index.php?go=supportercalendar">Volunteer/Supporter</a></li>
</ul>
</li>
</ul>
<ul>
<li>Programs <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=streetleader">StreetLeader</a></li>
<li><a href="index.php?go=afterschool">Afterschool Programs</a></li>
<li><a href="index.php?go=urbanpromiseschool">UrbanPromise School</a></li>
<li><a href="index.php?go=summercamps">Summer Camps</a></li>
<li><a href="index.php?go=internship">Internship</a></li>
</ul>
</li>
</ul>
<ul>
<li>Get Involved <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=donate">Donate</a></li>
<li><a href="index.php?go=volunteer">Volunteer</a></li>
<li><a href="index.php?go=workgroups">Workgroups</a></li>
<li><a href="index.php?go=store">Store</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href="index.php?go=blog"> Blog </a>
</li>
</ul>
</div>
我尝试将 display: inline 添加到 .menu 中,但没有效果,当我将其添加到 .menu ul 或将其添加到两者中时,这是 IE7 中的结果: http://img830.imageshack.us/img830/9855/ieresult.png
编辑 #2:解决方案:我使用 Google Code 上某人的项目修复了该问题,该项目使用 javascript 使 IE 的行为像更标准的浏览器。这是一个链接! http://code.google.com/p/ie7-js/
I've programmed a css dropdown menu that seems to be working correctly in every browser but Internet Explorer (at least in IE7).
Here's a link to a picture of how it looks when it behaves correctly (not enough rep to post pictures yet):
http : // img535imageshack.us/i/chromeexample.png/
Here's a link to how it looks in IE:
http : // img299.imageshack.us/i/ieexample.png/
If you want to view the whole website, it's at urbanpromise.org
Here's the css menu coding:
.menu{
width: 40em;
height: 2em;
background: #63089C;
float: left;
font-family: helvetica, arial, sans-serif;
}
.menu ul{
list-style: none;
float: left;
padding: .4em .75em;
margin: 0;
text-align: center;
font-weight: bold;
color: white;
}
.menu a{
text-decoration: none;
color: white;
}
.menu ul:hover{
color: black;
background: white;
}
.menu a:hover{
color: black;
background: white;
}
.menu ul ul{
position: absolute;
z-index: 500;
text-align: left;
}
div.menu ul ul{
display: none;
font-weight: normal;
}
div.menu ul li:hover ul{
display: block;
background: #63089C;
border: 0px solid black;
border-width: .125em 0;
}
Thanks in advance for the help.
Edit: Here is the HTML code for the menu:
<div class="menu">
<ul>
<li><a href="index.php?go=home"><span class="h2">Home</span></a></li>
</ul>
<ul>
<li>Information <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=staffandboard">Staff and Board</a></li>
<li><a href="index.php?go=historyandmission">History and Mission</a></li>
<li><a href="index.php?go=media">Media</a></li>
<!--<li><a href="index.php?go=speakerinfo">Speaker Information</a></li>-->
<li><a href="index.php?go=contactus">Contact Us</a></li>
</ul>
</li>
</ul>
<ul>
<li>Calendars <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=schoolcalendar">UrbanPromise School</a></li>
<li><a href="index.php?go=programcalendar">Summer/Afterschool</a></li>
<li><a href="index.php?go=supportercalendar">Volunteer/Supporter</a></li>
</ul>
</li>
</ul>
<ul>
<li>Programs <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=streetleader">StreetLeader</a></li>
<li><a href="index.php?go=afterschool">Afterschool Programs</a></li>
<li><a href="index.php?go=urbanpromiseschool">UrbanPromise School</a></li>
<li><a href="index.php?go=summercamps">Summer Camps</a></li>
<li><a href="index.php?go=internship">Internship</a></li>
</ul>
</li>
</ul>
<ul>
<li>Get Involved <img src="img/index/dropdown.png" width="13" height="8" alt="dropdown">
<ul>
<li><a href="index.php?go=donate">Donate</a></li>
<li><a href="index.php?go=volunteer">Volunteer</a></li>
<li><a href="index.php?go=workgroups">Workgroups</a></li>
<li><a href="index.php?go=store">Store</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href="index.php?go=blog"> Blog </a>
</li>
</ul>
</div>
I tried adding display: inline to .menu with no effect, and when I added it to .menu ul or added it to both this was the result in IE7:
http://img830.imageshack.us/img830/9855/ieresult.png
Edit #2: SOLUTION: I fixed the problem using someone's project on Google Code that uses javascript to make IE behave like a more standard browser. Here's a link!
http: //code.google.com/p/ie7-js/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能有双边距浮动错误或折叠父级浮动错误。
我会将
display: inline;
添加到.menu
和/或.menu ul
中。You probably have either a double margin float bug or a collapsed parent with floats bug.
I'd add
display: inline;
to.menu
and/or.menu ul
.