开发者

In IE 8/9 - cant click image, inside anchor that is wrapped with span using display:block

开发者 https://www.devze.com 2023-04-10 20:17 出处:网络
I\'ve got a bit of a problem creating a navigation element - its working fine in firefox, but seems to be causing me a headache in IE8/IE9. The other odd thing is that it works fine in IE on when runn

I've got a bit of a problem creating a navigation element - its working fine in firefox, but seems to be causing me a headache in IE8/IE9. The other odd thing is that it works fine in IE on when running under localhost, but not when run on a server.

I've tried to narrow down the actual issue, and开发者_如何学运维 its seems to be caused by me wrapping a couple of elements (an img and some text), in a span that has display:block. When I do this the image no longer responds to the href javascript of the anchor tag. Its kind of difficult to explain so I've included a cut down example:

<a title="My Link" href='javascript:alert(1);' style="display: block; height: 37px; text-decoration: none;">
    <span style="display: block; height: 34px;">
        <img title="My Icon" src="mypic.png" alt="ss" />
        <span>Link Text</span>
    </span>
</a>

Any help would be great!

Matt


The other odd thing is that it works fine in IE on when running under localhost, but not when run on a server.

In that case, the problem is to do with the rendering mode that IE is using. Hit F12 to bring up the Developer Tools to see which mode is being used.

Adding this to your <head> should sort the problem out:

<meta http-equiv="X-UA-Compatible" content="IE=edge">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号