2010-08-26 103 views
0

我有一个div,其大小可能随时间不同。需要适合div的背景图片

在我设置一个背景图像到达div div图像大小是固定的。 但我需要将背景图像适合任何尺寸的div。

怎么可能thro'CSS。

在此先感谢!

回答

1

使用CSS更改图像大小的唯一方法是当它是<img>元素。 我的意思是,你可以做这样的事情:

img#myBG { width:200px; height:100px; } 

如果你需要它的背景下,你应该使用“z-index的”,把你的img下保存内容的元素。

事情是这样的:

<div id="holder"> 
    <img id="myBG" src="...." /> 
    <div>my content here</div> 
</div> 

<style> 
#holder { position:relative; width:200px; height:100px; } 
#holder div { position:absolute; top:0; left:0; z-index:2; } 
img#myBG { width:200px; height:100px; { position:absolute; top:0; left:0; z-index:1; } 
</style>