gpt4 book ai didi

javascript - 将元素定位在图像元素上,但图像随窗口改变大小

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:58 24 4
gpt4 key购买 nike

我有一个图像,它的大小会随着窗口的大小而变化,我需要在其上放置一个元素( 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com