开发者

can you align an image with position:relative with an image that has position:absolute?

开发者 https://www.devze.com 2023-03-12 08:44 出处:网络
I have two images on a page. The first image has position:relative and the second image is right under the f开发者_C百科irst image with position:absolute. Is it possible to align the second image with

I have two images on a page. The first image has position:relative and the second image is right under the f开发者_C百科irst 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?


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.


Something like this?

0

精彩评论

暂无评论...
验证码 换一张
取 消