简体   繁体   English

IE7 -显示:块<a>内</a> <li> <a>无法正确显示</a>

[英]IE7 - display: block <a> within <li> does not display correctly

If you look at this code: http://jsfiddle.net/b3KaM/2/ 如果你看一下这段代码: http//jsfiddle.net/b3KaM/2/

in IE7 the <a> tags do not stretch to their parent <li> width even if display: block; 在IE7中,即使display: block; <a>标签也不会拉伸到其父<li>宽度display: block; is set. 已设定。 You can see the difference with the background color set to red on the list items and yellow on the links. 您可以看到与列表项上设置为红色的背景颜色和链接上的黄色的差异。

it obviously work fine in FF/Chrome & friends. 它显然在FF / Chrome和朋友中运行良好。

EDIT: the complication here is that I cannot set a fixed width - the link text should stay on one line and the whole list should expand as needed. 编辑:这里的复杂性是我不能设置固定宽度 - 链接文本应保持在一行,整个列表应根据需要扩展。

I'm aware that this as been asked before and I've found a few questions on SO but I could not find a valid solution to this issue - any ideas anyone? 我知道这是之前被问过的,我在SO上发现了一些问题,但是我找不到这个问题的有效解决方案 - 任何人的想法?

If not - is it safe to say that is not possible to achieve the same result on IE7 as on other browsers, ie it's an Internet Explorer bug with no workaround? 如果不是 - 可以肯定地说,在IE7上无法像在其他浏览器上那样获得相同的结果,即它是一个没有解决方法的Internet Explorer错误吗?

This problem is caused by a rendering phenomenon in IE7 and lower known as hasLayout . 此问题是由IE7中的渲染现象引起的,较低的已知为hasLayout

To fix the problem, you must simply prevent your a elements from "gaining layout". 为了解决这个问题,就必须简单地抑制你的a元素,从“获取布局”。

Unfortunately, there's massive list of stuff that causes an element to "gain layout" . 不幸的是,有大量的东西导致元素“获得布局”

Your a elements currently have overflow: hidden and min-height set. a元素当前有overflow: hiddenmin-height设置。 If you remove those properties, it will work in IE7. 如果删除这些属性,它将在IE7中工作。

使用块,您还必须为元素提供宽度。例如: - http://jsfiddle.net/b3KaM/8/

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

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