Html img 上的 href 链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3779812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:37:04  来源:igfitidea点击:

a href link on img

htmlcssinternet-explorer

提问by redcoder

Hi I have the following code to have few links on top of img. It works well in FF but not in IE. It seems IE is not clickable if you put link on top of img

嗨,我有以下代码可以在img. 它在 FF 中运行良好,但在 IE 中不起作用。如果您将链接放在上面,则 IE 似乎不可点击img

<div style="z-index:-6755;"><img alt="October Offer" src="images/offers/october-offer.jpg" /></div>
<a href="javascript:void(0);" onclick="window.parent.SqueezeBox.close();" style="text-decoration: none; width: 147px; height: 32px; position: inherit; bottom: 32px; left: 50px; border: 1px solid red; display: block;" target="_parent"> </a> 

<a href="#" onclick="window.parent.SqueezeBox.close();">
<div style="display:block; width: 185px; height: 32px; position: relative; bottom: 50px; left: 260px;border:1px solid blue; ">&nbsp;</div>
</a>

回答by Alex B

are you just trying to make the image clickable?

你只是想让图像可点击吗?

you can't have <href>that's not a correct html tag.

你不能让<href>那不是一个正确的 html 标签。

either place <img>inside <a>like so: <a href="http://www.example.com/"><img /></a>

或者像这样放在<img>里面<a><a href="http://www.example.com/"><img /></a>

another way is to set a div with a background image of your image and then a link inside there, make the link display : block and make it the entire width and height of the div and the whole thing will be clickable.

另一种方法是设置一个带有图像背景图像的 div,然后在其中设置一个链接,使链接显示 : 阻止并使其成为 div 的整个宽度和高度,整个内容都将是可点击的。