如何固定图像相对于不同屏幕尺寸的另一图像的位置
我正在编写一个网站/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
与其他答案类似,但如果您不想定义宽度和高度,可以使用
float
:http://jsfiddle.net/RprTY/
CSS:
只要将父容器设置为
position:relative
或position: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/
CSS:
As long as the parent container is set to either
position: relative
orposition: 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.将 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.
我尝试了这里提出的解决方案,但它不起作用。我基本上有同样的问题:滑块中的两个图像,其中一个是绝对位于百分比值的位置(因此,当我更改视口的宽度时,它侧面滚动)。另一个图像应与第一个相对于后者静态定位的第一个图像。
事实是,我的图像不是同一父母div的孩子。我已经设置了当前正在使用的代码的小提琴示例。
http://jsfiddle.net/36qpg/1/
我已经为这个问题苦苦挣扎了一段时间,但是我无法弄清楚。我希望我已经足够清楚了。
先感谢您。
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/
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.
html:
css:
html:
css: