IE7 中链接内的图像无法点击
IE7出现问题,这里有解释。
HTML
<a class="item" href="http://google.com">
<div class="itemImg">
<img src="http://img-fotki.yandex.ru/get/4512/vmazann.0/0_52db2_1c3135a9_orig.jpg" alt=""/>
</div>
<h3>Hello World</h3>
</a>
CSS
.item {
color: #140804;
cursor: pointer;
padding: 17px;
position: relative;
text-align: center;
text-decoration: none;
width: 142px;
display:block;}
.item * {
cursor: pointer;}
.itemImg {
background: none repeat scroll 0 0 red;
height: 150px;
line-height: 150px;
margin-bottom: 10px;
overflow: hidden;
text-align: center;
vertical-align: middle;}
.itemImg img {
vertical-align: middle;}
结果
http: //jsfiddle.net/qjSpS/11/
问题
在 IE7 中图像不可点击
我对问题的看法
看来问题与 hasLayout 属性设置有关.itemImg。如果我删除触发 hasLayout 的属性(高度:150px;和溢出:隐藏;),则图像将可点击
问题
有什么方法可以解决这个问题吗?高度:150px;和溢出:隐藏;是必需的属性。
Having a problem with IE7, here is explanation.
HTML
<a class="item" href="http://google.com">
<div class="itemImg">
<img src="http://img-fotki.yandex.ru/get/4512/vmazann.0/0_52db2_1c3135a9_orig.jpg" alt=""/>
</div>
<h3>Hello World</h3>
</a>
CSS
.item {
color: #140804;
cursor: pointer;
padding: 17px;
position: relative;
text-align: center;
text-decoration: none;
width: 142px;
display:block;}
.item * {
cursor: pointer;}
.itemImg {
background: none repeat scroll 0 0 red;
height: 150px;
line-height: 150px;
margin-bottom: 10px;
overflow: hidden;
text-align: center;
vertical-align: middle;}
.itemImg img {
vertical-align: middle;}
Result
Problem
In IE7 image is unclickable
My thoughts on problem
It seems that problem is related somehow with hasLayout property setting on .itemImg. If I remove properties that trigger hasLayout (height: 150px; and overflow: hidden;) then image will be clickable
Question
Is there any way to solve this problem? height: 150px; and overflow: hidden; are required properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 IE 中,您可能无法将内联元素
包裹在块级元素
或
周围>。
大多数浏览器都会忽略它并按照您的预期行事,但 IE 在这方面非常严格。
It may be that in IE you can not wrap an inline element
<a>
around block level elements<div>
or<h3>
.Most browser will ignore it and act how you'd expect, but IE is pretty strict on the matter.
这就是我解决这个问题的方法..而不是:
我这样做了:
工作得像个魅力。
THis is how i solved this problem..instead of:
i did this:
worked like a charm.
您是否注意到图像边缘的红色边框是可单击的?
我认为 div 是问题的原因。
你能去掉 div 吗?
我调整了你的例子来展示它如何在没有 div 的情况下工作:
http://jsfiddle.net/qjSpS/10/
编辑
还有一次: http://jsfiddle.net/qjSpS/14/
不完全高兴,但它已经使所有元素均可点击。
Have you noticed that with the image the red border around the edge is clickable?
I think the div is the cause of the problem.
can you do away with the div?
I tweaked your example to show how it might work without the div:
http://jsfiddle.net/qjSpS/10/
EDIT
had another go: http://jsfiddle.net/qjSpS/14/
Not completely happy but it has made all the elements clickable.