简体   繁体   English

IE7无序列表中的奇怪CSS行为

[英]Odd CSS behavior in IE7 unordered list

I have a drop down list that I'm trying to get working in IE7. 我有一个下拉列表,我正在尝试使用IE7。 Amongst other bugs, the one that has me beat is the anchors on hover not pushing the background to full padding height. 在其他错误中,让我击败的一个错误是悬停时的锚点没有将背景推到完整的填充高度。 It seems to stay within the dimensions of its li and ultimately the ul. 它似乎保持在其li以及最终ul的范围内。 I've tried expanding the height of both ul and li but this doesn't seem to work. 我尝试扩大ul和li的高度,但这似乎不起作用。 Works correctly in all other browsers: 在所有其他浏览器中均可正常运行:

http://jsfiddle.net/gzLVR/2/ http://jsfiddle.net/gzLVR/2/

What you should see: The anchor tag, on hover, should expand at the bottom by 50px (as per the css #menu > ul > li:hover > a { padding-bottom:50px; } . This expansion is performed, but the background-color doesn't seem to push to the anchor's margins. 您应该看到的是:锚定标记在悬停时应在底部扩展50px(按照css #menu > ul > li:hover > a { padding-bottom:50px; } 。 background-color似乎并没有增加锚点的边缘。

What am I doing wrong? 我究竟做错了什么?

IE7 does not support :hover on items other than <a> tags. IE7在<a>标记以外的项目上不支持:hover Since you have your :hover on an <li> it is not working in IE7. 由于您将:hover放在<li>因此它在IE7中不起作用。

You'll need to add some javascript to add a .hover class to the <li> when you mouseover, and then adjust your css to include it as well: 当您将鼠标悬停在<li>时,需要添加一些JavaScript来将.hover类添加到<li> ,然后调整css使其也包括在内:

#menu > ul > li:hover > a,
#menu > ul > li.hover > a{ 
    padding-bottom:50px; 
}

[EDIT] It appears this is only true when IE7 renders in quirksmode. [编辑]看来这仅在IE7以quirksmode渲染时才成立。 If you are using a strict doctype, you should be able to use :hover on an <li> 如果您使用严格的doctype,则应该可以在<li>上使用:hover

Have you tried changing the anchor to 您是否尝试过将锚点更改为

display:inline-block; 
zoom:1;

The zoom should only be required for IE7, it triggers ' hasLayout ' 只有IE7才需要zoom ,它会触发“ hasLayout

I think trigger hasLayout will fix it; 我认为触发器hasLayout将解决该问题; you can do it with somthin like this: 您可以使用somthin来做到这一点:

#menu > ul > li > a { display: inline-block;}

Be aware of that IE don't supports :last-child up to IE8 , but you can use :first-child . 请注意,IE不支持:last-child 直至IE8 ,但是您可以使用:first-child

I would also suggest to use a pseudo element for the part you used the <i></i> , so you don't have unneccessary markup in your HTML. 我还建议对使用<i></i>的部分使用伪元素,以免HTML中没有不必要的标记。

I ended up finding the solution myself. 我最终自己找到了解决方案。 Each li's anchors are by default set to wrap around it's content (display:inline?), and setting the display to inline-block is somewhat dangerous as its behavior in IE7 is somewhat unpredictable. 默认情况下,每个li的锚点都设置为环绕其内容(display:inline?),并且将显示设置为inline-block有点危险,因为它在IE7中的行为是无法预测的。

By simply setting the anchor to display:block, you allow it to take on dimensions of itself in IE7, so you break it away from having it simply wrap around its content. 通过简单地将锚设置为display:block,就可以使其在IE7中具有自身的尺寸,因此您不必将其简单地包裹在其内容中即可。 Thus, it's possible for it to affect the needed padding when on hover. 因此,悬停时可能会影响所需的填充。

This will now work in IE7: http://jsfiddle.net/gzLVR/5/ 现在可以在IE7中使用: http : //jsfiddle.net/gzLVR/5/

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

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