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