1

我正在尝试制作一个“背景”图像,它既可以缩放以填充屏幕,又是固定的(即不会随其余内容滚动。)

我首先尝试使用真实的背景图片:

background: url(http://i.imgur.com/DJaWd.jpg) no-repeat center center fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;

但您可能知道,使用这种技术,图像会在 iOS 设备上滚动。因此,我使用 CSS 和 div 尝试了这种方法:

CSS:

#fixedbg{
background:url('/images/contest_bkg.jpg') no-repeat center center;
position:fixed;
height:100%;
width:100%;
z-index:-1;
top:0;
}

第二种方法确实阻止了图像滚动,但图像显示为 1:1,而不是缩放以适应屏幕/视口大小。关于如何在保持锁定状态时缩放图像的任何提示?

4

1 回答 1

0

Try this:

-webkit-background-size: 1600px 1060px;

Of course px is width height of your bakcground image

于 2013-10-28T15:47:57.653 回答