2010-08-26 92 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>