简体   繁体   English

如何使图像可点击?

[英]How do I make an image clickable?

Here is the html:这是 html:

<div id="panelpic1">
    <a href="https://www.google.com/"style="display:block"target="_blank">
    </a>
</div>

CSS: CSS:

  #panelpic1{
            content: url(file:///D:/MOHIT/HTML/images.jpg);
            float: left;
            width: 250px;
            height: 150px;
            vertical-align: middle;               
           }

This is the way I did it, but it is not working.这是我做的方式,但它不工作。 The image is not clickable.图片不可点击。 What to do?该怎么办?

 <!DOCTYPE html> <html> <body> <span>Open image link in a new tab: <a href="http://www.google.com" target="_blank"> <img src="D:/MOHIT/HTML/images.jpg" /> </a> </span> </body> </html>

This is not the best approach.这不是最好的方法。 Here is one of the standard approaches to make image clickable.这是使图像可点击的标准方法之一。

<a href="your landing page url">
 <img src="your image url" />
</a>

Now, this image will redirect to you on specified URL on click.现在,此图像将在单击时重定向到指定的 URL。

There are many ways to do it from uploading it S3/dropbox to using FSCollection (that's for node users only).从上传 S3/dropbox 到使用 FSCollection(仅适用于节点用户),有很多方法可以做到这一点。

So in your case, your snippet will look like this,所以在你的情况下,你的片段看起来像这样,

<a href="http://www.google.com">
 <img src="D:/MOHIT/HTML/images.jpg" />
</a>

In agreement with @mukul-jain, I am updating his answer with a key clarification, as both the question and the answer are important for people new to HTML.与@mukul-jain 一致,我更新了他的回答并做了关键说明,因为问题和答案对于 HTML 的新手都很重要。

Update: img element in HTML5 is self-closing and does not need /更新:HTML5中的img元素自闭,不需要/

I most point out that HTML5 img element does not need a closing / as in the answer from five years ago.我最指出的是 HTML5 img元素不需要像五年前的答案那样结束/ Thus, I have revised the answer below to comply with this:因此,我修改了以下答案以符合这一点:

<a href="http://www.google.com">
 <img src="D:/MOHIT/HTML/images.jpg">
</a>

Notice the original answer has / in before > , which is not needed for img elements (see references below).请注意,原始答案在>之前有/img元素不需要它(请参阅下面的参考资料)。 Other than this, his answer is correct on how to make an image clickable, that is, to turn an image into a link.除此之外,他关于如何使图像可点击的答案是正确的,即将图像变成链接。

Supporting Documentation:支持文档:

Cheers!干杯!

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

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