2011-12-09 143 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