2012-11-05 138 views
0

我在网页上使用了一个背景图片,并在css中使用了这个代码,这使得在浏览器调整大小时可以很好地调整大小。当浏览器调整大小时,CSS图像变得更小

body{ 
    background: url("images/back.jpg") no-repeat ; 
    background-size: cover; 
} 

我需要放置在背景图像上的一些其他图像的特定位置(上表的花瓶)。但,当我这样做,那么后台获取大小,但花瓶形象留在同一个地方,调整浏览器大小时的大小相同,如下面的第二张图所示。

看到了花瓶这两个图像

browser in full size

resized browser

我怎样才能让这个花瓶形象也得到调整大小就像背景

+0

您使用的是你的形象是什么CSS? –

+0

将两幅图像组合成一幅图像如何? –

+0

比利有一个鼠标悬停,它改变了花瓶的颜色,这就是为什么它必须是另一个图像 – JanetOhara

回答

0

尝试使图像的相对位置和手动设置对齐。

http://jsfiddle.net/cfjbF/1/

<head> 
    <style> 
     body { 
      background: #000000; 
     } 

     #image1 { 
      background: #008000; 
      position: relative; 
      left: 50px; 
      height: 50px; 
      width: 50px; 
     } 
    </style> 
</head> 
<body> 
<div id="image1"></div> 
</body> 
1

我最近碰到了一模一样的问题创建一个隐藏的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/

相关问题