简体   繁体   English

IE7 CSS水平菜单-Li似乎相互嵌套

[英]IE7 CSS Horizontal Menu - Li's seem to be nesting within each other

I know this IE problem comes up time and time again but I have spent all morning searching for answers and none seem to help me. 我知道这个IE问题一次又一次地出现,但是我花了整整一个上午的时间寻找答案,但似乎都没有帮助。

My horizontal navigation menu seems to render perfectly in all browsers except for IE7. 我的水平导航菜单似乎可以在除IE7之外的所有浏览器中完美呈现。 I am thinking the problem could possibly be to do with my lists having no widths (but I do not want widths, I want it to be automatic depending on the length of the text), either that or the li's seem to be sitting within each other and keep applying the 14px padding-top. 我认为问题可能与我没有宽度的列表有关(但我不希望宽度,我希望它是自动的,具体取决于文本的长度),或者李似乎坐在每个列表中其他,并继续应用14px的padding-top。 I do not know why they are sitting inside each other though as my li's all have closing tags and a float:left; 我不知道他们为什么彼此坐在一起,尽管我的李全都有关闭标签和float:left;

Here is my code.. 这是我的代码。

<div id="navig">
    <ul>
        <li class="navig-left"></li>
        <li class="home"><b>Home</b></li>
        <li><a class="tabs" href="about.html">About Us</a></li>
        <li><a class="tabs" href="services.html">Services</a></li>
        <li><a class="tabs" href="personal-injury-panel.html">Personal Injury Panel</a></li>
        <li><a class="tabs" href="client-testimonials.html">Client Testimonials</a></li>
        <li><a class="tabs" href="contact.html">Contact Us</a></li>
        <li><a class="tabs" href="careers.html">Careers</a></li>
        <li><a class="tabs" href="affiliates.html">Affiliates</a></li>
        <li class="navig-right"></li>
    </ul>
</div>

<div class="clr"></div>



#navig { width:960px; height:46px; background:url(images/navig_bkgrnd.png); }
#navig ul { list-style-type:none; height:46px; width:960px; }
#navig ul li.active { float:left; height:32px; text-align:center; display:block; padding:14px 21.3px 0; background:url(images/navig_hover.gif) repeat-x; color:#000000; font-weight:200; font-size:14px; font-style:normal; }
#navig ul li.home { float:left; height:32px; text-align:center; display:block; padding:14px 21.3px 0; color:#ffffff; font-weight:200; font-size:14px; }
#navig ul li a.tabs { float:left; height:32px; text-align:center; display:block; padding:14px 21.3px 0; text-decoration:none; color:#FFFFFF; font-weight:200; font-size:14px; font-style:normal; }
#navig ul li a:hover { display:block; text-decoration:none; height:32px; font-family:Arial, Helvetica, sans-serif; color:#000000; font-weight:200; font-size:14px; font-style:normal; background:url(images/navig_hover.gif) repeat-x; }
.navig-left { float:left; width:23px; height:46px; background:url(images/navig_left.png); }
.navig-right { float:left; width:23px; height:46px; background:url(images/navig_right.png); } 

Try adding the following CSS rule so that all li items float (since you're using a float approach): 尝试添加以下CSS规则,以使所有li项目都浮动(因为您使用的是float方法):

#navig ul li {float:left;}

Looking at your stylesheet, you don't actually apply float:left to all of the list items in the menu, only li.active and li.home . 查看样式表,实际上并没有将float:left应用于菜单中的所有列表项,只有li.activeli.home Other browsers seem to deal with it but IE doesn't like it. 其他浏览器似乎可以处理它,但IE不喜欢它。

jsFiddle (note I had to modify some colors to get it working since you are using white text over background images we don't have access to - causing white on white for testing purposes.) jsFiddle (请注意,我必须修改一些颜色才能使其正常工作,因为您在无法访问的背景图像上使用白色文本,导致白色为测试目的而产生白色。)

I tested this fiddle in IE 7/8/9, FF and Chrome. 我在IE 7/8/9,FF和Chrome中测试了这个小提琴。 Works consistently now. 现在可以连续工作。

您可以强制IE7渲染为ie8,并将其添加到页面的头部。

<meta http-equiv="X-UA-Compatible" content="EDGE" /> 

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

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