2013-08-01 253 views
0

我想弄清楚如何锁定div的背景图像的大小。我希望能够放大页面的大小,同时保持背景图像的大小相同,只需更改裁剪因子。试图做一些类似的... http://developers.kippt.com/锁背景图像大小

.div{ 
    background-image: url(../img/background-image.png); 
    background-repeat: no-repeat; 
    margin: 0 auto; 
    width: 100%; 
    height: 600px; 
    display: block; 
    position: relative; 
} 

回答

0

您可以使用

//this will scale the background image as large as possible to cover the whole div 
background-size:cover; 

//for fixed positioning 
background-attachment:fixed; 
//to make it center (or center top, depends on your need) 
background-position:center center; 

约背景大小的更多信息,你可以阅读文章here

+0

谢谢!工作很好。 – Brad

0

我用these techniques之前,他们都很好地工作。如果您阅读每个版本的优点/缺点,您可以决定哪种版本适合您的网站。

或者,如果您想脱离上述错误,则可以使用full size background image jQuery plugin

+0

不只是添加链接,描述实际的技巧,并添加链接作为一个额外的。如果您链接到的网站有变化,您的答案变得毫无用处... – Pevara