简体   繁体   English

IE6和IE7导航间距问题

[英]IE6 and IE7 Navigation spacing issue

I'm having a menu spacing issue in IE7 and IE6 that I cannot get to look right. 我在IE7和IE6中遇到菜单间距问题,无法正确查看。

My navigation can be found at http://js.philosophydesign.com 我的导航位于http://js.philosophydesign.com


(source: philosophydesign.com ) (来源: Philosophdesign.com

As you can see in IE8 and others it displays fine. 正如您在IE8和其他版本中看到的那样,它可以正常显示。 IE7 the menu items are partially seperated but in IE6 they are seperated hugely. IE7中的菜单项是部分分离的,但在IE6中,它们是巨大分离的。

Navigation HTML: 导航HTML:

<a class="float-left" href="http://js.philosophydesign.com"><img src="http://js.philosophydesign.com/wp-content/themes/philosophy/images/logo.gif" alt="Jeremy Stratton - Writing that works" title="Jeremy Stratton - Writing that works" /></a>
<div id="mainnavcont" class="float-right">
  <ul id="mainmenu" class="menu">
    <li id="menu-item-25" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-6 current_page_item menu-item-25"><a href="http://js.philosophydesign.com/">I get to your point</a></li>
    <li id="menu-item-26" class="menu-item menu-item-type-post_type menu-item-26"><a href="http://js.philosophydesign.com/me-and-my-work/">Me and my work</a></li>
    <li id="menu-item-27" class="menu-item menu-item-type-post_type menu-item-27"><a href="http://js.philosophydesign.com/things-ive-written/">Some of the things I’ve written</a></li>
    <li id="menu-item-28" class="menu-item menu-item-type-post_type menu-item-28"><a href="http://js.philosophydesign.com/improve-your-writing/">Improve your writing</a></li>
    <li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-29"><a href="http://js.philosophydesign.com/what-people-say-about-me/">What people say about me</a></li>
    <li id="menu-item-30" class="menu-item menu-item-type-taxonomy menu-item-30"><a href="http://js.philosophydesign.com/category/my-blog/">My blog</a></li>
    <li id="menu-item-31" class="menu-item menu-item-type-post_type menu-item-31"><a href="http://js.philosophydesign.com/get-in-touch/">Get in touch</a></li>
  </ul>
</div>

Navigation CSS: 导航CSS:

/**** Main Navigation ****/
div#mainnavcont {
    float:right;
    width:673px;
}
ul#mainmenu {
    display:block;
    list-style:none;
    margin:0;
    padding:0;
}
ul#mainmenu li a {
    color:#000;
    display:block;
    font-family:"HelveticaNeueLight45", "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size:12px;
    font-weight:normal;
    padding-left:10px;
    margin-left:-10px;
    text-decoration:none;
}
ul#mainmenu li a:hover, ul#mainmenu li.current-menu-item a, ul#mainmenu li.current-page-ancestor a {
    background:url(images/navbg.png) no-repeat 5px 50%;
}

Anyone know why this menu is acting up in IE7 and IE6? 有人知道为什么该菜单在IE7和IE6中起作用吗?

Thanks 谢谢

Scott 史考特

EDIT: Got it working with this css: 编辑:得到了与此CSS工作:

/**** Main Navigation ****/
div#mainnavcont {
    float:right;
    width:673px;
}
ul#mainmenu {
    display:block;
    list-style:none;
    margin:0;
    padding:0;
    width:200px;
}
ul#mainmenu li {
    display:block;
    float:left;
    width:200px;
}
ul#mainmenu li a {
    color:#000;
    display:block;
    font-family:"HelveticaNeueLight45", "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size:12px;
    font-weight:normal;
    padding-left:10px;
    margin-left:-10px;
    text-decoration:none;
    width:189px
}
ul#mainmenu li a:hover, ul#mainmenu li.current-menu-item a, ul#mainmenu li.current-page-ancestor a {
    background:url(images/navbg.png) no-repeat 5px 50%;
}

This is the "mysterious space between list items" that sometimes shows up in IE. 这是IE中有时会显示的“列表项之间的神秘空间”。 Often it happens when the list item and link inside have different display types, or hasLayout is inconsistently applied. 通常,当列表项和内部链接具有不同的显示类型或hasLayout应用不一致时,会发生这种情况。 But the whole scenario is affected by a combination of display, line-height, and hasLayout. 但是整个情况都受到显示,行高和hasLayout的组合的影响。 :-) :-)

This gets them all to the same starting point (or it does in IE7, which is what I have at the moment.) I think the big issue for you was that you set #mainmenu and #mainmenu a to display:block but had left #mainmenu li at its default. 这使它们全部到达相同的起点(或者在IE7中也是如此,这就是我目前所拥有的。)我认为对您来说,最大的问题是您将#mainmenu和#mainmenu a设置为display:block但已离开#mainmenu li是默认设置。

#mainnavcont {
    float:right;
    width:673px;
}
#mainmenu, #mainmenu li, #mainmenu a {
    display:block;
    margin:0;
    padding:0;
    line-height:1;
    list-style:none;
}
#mainmenu {}
    #mainmenu li {}
        #mainmenu a {
            margin-left:-10px;
            padding-left:10px;
            color:#000;
            font-family:"HelveticaNeueLight45", "Trebuchet MS", Arial, Helvetica, sans-serif;
            font-size:12px;
            font-weight:normal;
            text-decoration:none;
        }
            #mainmenu a:hover, #mainmenu .current-menu-item a, #mainmenu .current-page-ancestor a {
                background:url(images/navbg.png) no-repeat 5px 50%;
            }

You can see some examples of various situations where this occurs by viewing http://www.brunildo.org/test/IEWlispace.php in IE. 通过在IE中查看http://www.brunildo.org/test/IEWlispace.php ,可以查看发生这种情况的各种示例。 At the bottom of that site he mentions various fixes for various causes. 在该站点的底部,他提到了各种原因引起的各种修复。

If this doesn't get you all the way there also check out: 如果这还不能解决问题,还请查看:

http://gtwebdev.com/workshop/gaps/white-space-bug.php http://gtwebdev.com/workshop/gaps/white-space-bug.php

There are some other solutions out there as well, but I can't find my favorite reference right now. 还有一些其他解决方案,但是我现在找不到我最喜欢的参考。 :-( :-(

Related Tip 相关提示

If you end up needing more rules for just IE7 or IE6, check out this method of http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ targeting IE. 如果您最终只需要针对IE7或IE6的更多规则,请查看针对IE的http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-noth/的此方法。

Unrelated Tip: 不相关的提示:

If you don't absolutely need the tag name to increase your rule's specificity, it's best to omit it. 如果您绝对不需要标签名称来增加规则的特异性,则最好将其省略。 Not just because it makes your selectors shorter, but because of the way browsers parse and apply CSS. 不仅仅是因为它使选择器更短,还因为浏览器解析和应用CSS的方式。 They start at the end of the rule, so in 它们从规则的结尾开始,所以在

ul#mainmenu li a

Worst case scenario the browser: finds all a, checks for li parents, checks for #mainmenu parents, and then checks that #mainmenu is a ul. 最糟糕的情况是浏览器:找到所有a,检查li父母,检查#mainmenu父母,然后检查#mainmenu是ul。 This is superfluous and inefficient, especially when you add in the fact that element selectors are (according to browser vendors) less efficient than classes and ids. 这是多余且低效的,尤其是当您添加(根据浏览器供应商)元素选择器的效率低于类和id的事实时。 (Which means if you have a class like .menu-item on the li it's better to use that in your selector than li.) (这意味着,如果在li上有类似.menu-item的类,则最好在选择器中使用它而不是li。)

Few things I'd check based upon the 'Vertical Spacing or Whitespace Bug' section of this article which has some nice examples - it's usually something to do with margins, padding and floating/clearing to get everything nice and consistent cross browser. 几件事情我会找基于“垂直间距或空白错误”的一节这篇文章它有一些很好的例子-它通常是一些与边距,填充和浮动/清除办得到的一切好的和一致的跨浏览器。

HTH 高温超导

I suppose setting line-height:1; 我想设置line-height:1; for .menu-item will fix the problem (maybe line-height:1 is not exactly what you need, play with the values, maybe 1.25 is the best) for .menu-item将解决此问题(也许line-height:1并不是您所需要的,请.menu-item使用值,也许1.25是最好的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM