我有一个图像,它的大小会随着窗口的大小而变化,我需要在其上放置一个元素( anchor 标记),以便它始终位于与图像相关的同一位置。该图像不是背景图像,而是 HTML 元素。
这个问题非常相似,但适用于图像是背景图像的情况。 Position element over background image. But the BG img changes size with the window. CSS
<img src="images/img.jpg" >
<a href="3">Link that should be over the image in a certain location.</a>
最佳答案
<div class="wrapper">
<img src="images/img.jpg">
<a href="3">Link that should be over the image in a certain location.</a>
</div>
<style>
.wrapper {
position: relative;
}
a {
position: absolute;
top: 10%;
left: 10%;
}
</style>
关于javascript - 将元素定位在图像元素上,但图像随窗口改变大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485682/