IE7 下拉菜单
正如 Sotiris 所提到的,IE7 最简单的修复方法是为 ul#menu > li > ul 提供固定宽度。这将导致子 <li> 和 <a> 元素正确地占据其父元素宽度的 100%。
目前在 IE7 中发生的情况是,您的下拉菜单宽度取决于 white-space: nowrap 属性的最长子元素的长度。然后 IE7 不会正确地将其应用于下拉列表的 <ul>,而是从顶级菜单项(在您的情况下为 104 像素)获取其宽度。
如果您仍想保留动态宽度菜单,您可以在 IE7 中使用 jQuery 的 sn-p 来修复它,它会在加载时循环遍历所有链接,找到最宽的链接并将父级 <ul> 设置为该宽度.它应该在您的$(window).load 事件处理程序中运行,就在您将所有ul#menu > li ul 设置为显示:块:
// Nodig om de width te kunnen raadplegen
$("ul#menu > li ul").css("display", "block");
// Loop through all dropdowns and find widest child link in each
$('ul.children').each(function(){
// Find widest link in each submenu
var widest = 0;
$(this).children('li').each(function(){
if($(this).width() > widest)
widest = $(this).width();
});
// Set submenu width to widest child link
if(widest != 0)
$(this).width(widest);
});
要修复居中的项目,您还需要从此规则中删除 text-align: center:
ul#menu > li{
background: url(img/menuitem.png) left top;
display: block;
float: left;
height: 36px;
margin-right: 1px;
position: relative;
width: 104px;
}
最后,您需要确保在下拉链接上正确设置了hasLayout 标志。您可以通过在以下规则上设置zoom: 1 来做到这一点:
ul#menu > li > a, ul#menu > li > ul a {
zoom: 1;
display: block;
text-decoration: none;
white-space: nowrap;
}
Firefox 3.5 子菜单指示器
这是一个更容易解决的问题。添加ul#menu > li > ul > li a 声明并更改您的span.sf-sub-indicator 规则如下:
/* Makes the link a coordinate map for span.sf-ub-indicator */
ul#menu > li > ul > li a {
position: relative;
padding-right: 10px;
}
ul#menu > li > ul > li a > span.sf-sub-indicator {
position: absolute;
top: 0;
right: 0;
}
这绝对会将指示器定位在链接的最右侧。请注意,您还需要对 IE7 应用此修复程序,否则您的子菜单将被下推一个链接。