我最近碰到了一模一样的问题创建一个隐藏的OBJ ect游戏需要放置在背景图像顶部的图像以保持其位置,而不管浏览器尺寸如何。
这里就是我所做的:
可以包括背景图像的模板版本作为实际<img>
与visibility:hidden
(所以它是不可见的,但仍然占据了它的空间在DOM和基本尺寸(和背景图像的大小)的基础上该
HTML:
<div class="image-container">
<img src="http://www.w3.org/html/logo/downloads/HTML5_Logo_512.png" class="img-template">
<div class="item"></div>
</div>
CSS:
/* This is your container with the background image */
.image-container {
background:url('http://www.w3.org/html/logo/downloads/HTML5_Logo_512.png') no-repeat;
background-size:100%;
overflow-x: hidden;
position:relative;
}
/* This is the template that resizes the DIV based on background image size */
img.img-template {
visibility: hidden;
width:100%;
height:auto;
}
/* This is the item you want to place (plant pot) */
.item {
position: absolute;
left: 14.6%;
bottom: 80.3%;
width: 15%;
height: 15%;
background: yellow;
border: 2px solid black;
}
这里是一个工作示例:http://jsfiddle.net/cfjbF/3/
您使用的是你的形象是什么CSS? –
将两幅图像组合成一幅图像如何? –
比利有一个鼠标悬停,它改变了花瓶的颜色,这就是为什么它必须是另一个图像 – JanetOhara