如何固定图像相对于不同屏幕尺寸的另一图像的位置

发布于 2024-12-05 06:30:50 字数 250 浏览 0 评论 0原文

我正在编写一个网站/iPad应用程序(使用 phonegap ),在幻灯片节目中,我有1024x768图像。我想在1024x768图像的顶部放置另一个图像,例如,在屏幕尺寸(例如高/低分辨率PC屏幕)或1024x768平板电脑显示屏上,位置完全相同的位置。我尝试了绝对的,但是位置在不同显示中的变化,并且与我最初在CS 5中设置的位置不同。

I'm writing a website/iPad app (using PhoneGap), where I have 1024x768 images on a slide show. I'd like to position another image, e.g. the home icon, on top of the 1024x768 images, at exactly the same position, no matter the screen size (e.g. high/low resolution PC screen, or 1024x768 tablet display). I tried absolute, but the position changes in different displays, and it's not the same position as I originally set up in CS 5.

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

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

发布评论

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

评论(4

妖妓 2024-12-12 06:30:50

与其他答案类似,但如果您不想定义宽度和高度,可以使用 float

http://jsfiddle.net/RprTY/

<div>
    <img src="http://placekitten.com/300/300">    
    <img src="http://placekitten.com/30/30" id="smallone">
</div>

CSS:

div{
    float: left;
    position: relative;
}

img{
     vertical-align: bottom;   
}

#smallone{
    top: 0;
    left:0;
    position:absolute;   
}

只要将父容器设置为 position:relativeposition:absolute,那么绝对定位的图像应该相对于左上角定位父母的。这应该完全独立于屏幕分辨率。

Similar to the other answers, but if you prefer not to define the width and height, you can use float:

http://jsfiddle.net/RprTY/

<div>
    <img src="http://placekitten.com/300/300">    
    <img src="http://placekitten.com/30/30" id="smallone">
</div>

CSS:

div{
    float: left;
    position: relative;
}

img{
     vertical-align: bottom;   
}

#smallone{
    top: 0;
    left:0;
    position:absolute;   
}

As long as the parent container is set to either position: relative or position: absolute, then the absolutely positioned image should be positioned relative to the top left corner of the parent. This should be completely independent of screen resolution.

和影子一齐双人舞 2024-12-12 06:30:50

将 1024x768 图像放入相同大小的 div 中。也将您的主页图标包含在该 div 中。给 div 相对位置,给主页图标绝对位置,它将绝对定​​位在其父 div 内。

Put your 1024x768 image in a div of the same size. Include your home icon in that div as well. Give the div position relative, and the home icon position absolute and it will be absolutely positioned inside it's parent div.

雄赳赳气昂昂 2024-12-12 06:30:50

我尝试了这里提出的解决方案,但它不起作用。我基本上有同样的问题:滑块中的两个图像,其中一个是绝对位于百分比值的位置(因此,当我更改视口的宽度时,它侧面滚动)。另一个图像应与第一个相对于后者静态定位的第一个图像。

事实是,我的图像不是同一父母div的孩子。我已经设置了当前正在使用的代码的小提琴示例。

http://jsfiddle.net/36qpg/1/

<div class="image">
    <img id="back" src="http://placekitten.com/300/300" />
</div>
<div class="slide">
    <div class="image">
        <img id="front" src="http://www.lionsclublagardiecastelnau.com/data/images/images-sites/images/icone-android.png"></img>
    </div>
</div>

我已经为这个问题苦苦挣扎了一段时间,但是我无法弄清楚。我希望我已经足够清楚了。

先感谢您。

I tried the solution proposed here but it didn't work. I have basically the same problem: two images inside a slider, one of them is absolute positioned with percentage values (so when I change the width of the viewport it scrolls sideways). The other image should move along with the first one statically positioned in relation to the latter.

The thing is in my case the images are not children of the same parent div. I have set up a Fiddle example of the code I am currently working with.

http://jsfiddle.net/36QPG/1/

<div class="image">
    <img id="back" src="http://placekitten.com/300/300" />
</div>
<div class="slide">
    <div class="image">
        <img id="front" src="http://www.lionsclublagardiecastelnau.com/data/images/images-sites/images/icone-android.png"></img>
    </div>
</div>

It's worth mentioning that I can't change the HTML code set up.

I've been struggling with this problem for a while now, but I haven't been able to figure it out. I hope I've made myself clear enough.

Thank you in advance.

我是有多爱你 2024-12-12 06:30:50

html:

<div id="bottom">
    <div id="top"></div>
</div>

css:

#bottom{ 
    background: url(*bottom-image-url*); 
    position: relative; 
    width: *??*; 
    height: *??*;}
#top{ 
    background: url(*top-image-url*); 
    position: absolute; 
    width: *??*; 
    height: *??*; 
    left: *??*; 
    right: *??*;}

html:

<div id="bottom">
    <div id="top"></div>
</div>

css:

#bottom{ 
    background: url(*bottom-image-url*); 
    position: relative; 
    width: *??*; 
    height: *??*;}
#top{ 
    background: url(*top-image-url*); 
    position: absolute; 
    width: *??*; 
    height: *??*; 
    left: *??*; 
    right: *??*;}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文