html - 超链接图片

标签 html css

根据我当前的代码,我将如何为图像添加超链接,以便当用户单击图像时,浏览器会打开一个新选项卡并显示该图像?

body {
  margin: 0;
  padding: 0;
}

.img {
  display: grid;
  height: 100%;
}

.center-fit {
  max-width: 100%;
  max-height: 100vh;
  margin: auto;
}
<div class="img"> <img class="center-fit" src='https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Collage_of_Nine_Dogs.jpg/1363px-Collage_of_Nine_Dogs.jpg'></div>

最佳答案

这是最简单的方法。

<a href='https://anywebsite.com/home'> 
    <img class="center-fit" src='https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Collage_of_Nine_Dogs.jpg/1363px-Collage_of_Nine_Dogs.jpg' />
</a>

您可以将 anchor 标记 (<a href='...'> </a>) 包裹在任何东西周围,它会将它超链接到任何东西。

您还可以添加 <a href='...' target='_blank' </a>它会

关于html - 超链接图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53999444/

相关文章:

html - 在图像下方显示下拉值

php - 表格: Post to multiple action or one based on input?

javascript - Angular 7 router-outlet 设置高度大于窗口

html - 如何仅为移动版本创建 div?

javascript - 我无法使用宽度和高度属性正确地重新缩放 <canvas>

html - 修复警报框的高度定义

css - 在 div 上设置 CSS 100% 高度

html - 按下按钮时导航栏在右侧中断

css - 如何从 ckeditor 内容和数据生成 pdf?

c++ - Qt QCombobox 更改滚动箭头