我最近碰到了一模一樣的問題創建一個隱藏的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