2011-12-09 142 views

回答

0

一個快速谷歌搜索想出了(我沒有測試過,但谷歌是一個可愛的好朋友):

<style type="text/css"> 
    html, body { 
    height: 100%; 
    margin: 0; 
    padding: 0; 
    } 
    img#bg{ 
    position:fixed; 
    top:0; 
    left:0; 
    width:100%; 
    height:100%; 
    } 
    #content { 
    position:relative; 
    z-index:1; 
    } 
</style> 

編輯:DERP。忘記樣本HTML

</head> 

    <body> 

    <img src="size-bg.jpg" alt="background image" id="bg" /> 
    <div id="content">Your website content.</div> 

    </body> 
</html> 

從鏈接:http://dipaksblogonline.blogspot.com/2011/01/ie-78-stretching-background-image-to.html

+0

謝謝!我看到了這一個。它爲整個頁面繪製背景,但我只需要它爲div。這裏[http://i.stack.imgur.com/gql45.jpg](http://i.stack.imgur.com/gql45.jpg)就是例子。我的問題是高度:100%的圖片使得div太大。 – Xeon

+0

如何將圖片大小調整爲所需的大小,然後將其設置爲僅用於div的背景網址?當然,這是一個破解解決方案... – Gobbledigook

+0

Yeap,我這樣做。我用'display:none'樣式放了'img'。然後在文檔準備就緒的情況下,我將圖像大小調整爲div大小並設置「display:block」。骯髒但工作的解決方案:) – Xeon