您可以将具有位置:相对的图像与具有位置:绝对的图像对齐吗?

发布于 2024-11-14 17:49:11 字数 93 浏览 3 评论 0原文

我在一页上有两个图像。第一个图像的位置:相对,第二个图像位于第一个图像的正下方,位置:绝对。是否可以将第二张图像与另一张图像对齐,以便在放大或缩小时它们的相对位置保持不变?

I have two images on a page. The first image has position:relative and the second image is right under the first image with position:absolute. Is it possible to align the second image with the other one so that their relative positions remain the same as you zoom in or out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞美少年 2024-11-21 17:49:11

如果您使用浏览器进行缩放,则元素位置崩溃是很常见的情况。所以我不建议你太关注它。但无论如何,您的图像必须具有相同的父级,即具有“位置:相对”。

HTML

<div class="myImageContainer">
    <img class="positionedRelative" src="" alt="" />
    <img class="positionedAbsolute" src="" alt="" />
</div>

CSS

.myImageContainer { position: relative; }
img.positionedRelative { position: relative; } /* not necessary, try to remove */
img.positionedAbsolute { position: absolute; left: 0; top: 0; }

左:0;顶部:0; - 插入您自己的价值观。

If you zoom with your browser, crashing elements position is an ordinary situation. So I'd not advise you to pay so much attention to it. But in any case your images must have the same parent, that has "position: relative".

HTML

<div class="myImageContainer">
    <img class="positionedRelative" src="" alt="" />
    <img class="positionedAbsolute" src="" alt="" />
</div>

CSS

.myImageContainer { position: relative; }
img.positionedRelative { position: relative; } /* not necessary, try to remove */
img.positionedAbsolute { position: absolute; left: 0; top: 0; }

left: 0; top: 0; - insert your own values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文