2013-08-06 51 views
1

我需要一个固定的背景来获得浏览器的大小,并保持在这个大小,所以内容将向下滚动,左,右,但背景保持固定在后面。 用ipad2可以实现这个吗?css ipad 2在背景上滚动的网站内容固定

background: url("....") no-repeat fixed; 
background-size: auto; 
background-repeat: no-repeat; 
background-attachment: fixed; 

这样,baground以正确尺寸加载,但在滚动时滚动并显示背景颜色。

+0

iPad的类型是不相关的 - 它是iOS版本(并且这样的Safari版本)的事项。至于问题本身 - 这应该很好。你是否将背景应用于'body'? –

+0

背景直接应用于html标签,所以它应该背后的一切,这是正确的吗? – user2239318

回答

1

要做到这一点,你可以使用background-size: cover;

我不知道我理解这个问题。如果目标是设计一个iPad 2的具体背景,你可以做这样的事情与iPad的分辨率记即How large is the usable area in iPad Safari

@media screen and (max-width:1024px) { 
    body { 
     background:url(your-1024x690-image) fixed no-repeat; /*landscape background*/ 
    } 
} 

@media screen and (max-width:768px) { 
    body { 
     background:url(your-768x946-image) fixed no-repeat; /*portrait background*/ 
    } 
} 

没有测试它,但应该做的伎俩。

+0

问题在于,对于高度非常高的页面,背景会伸展到高度,但我希望它保持在其真实的维度。 – user2239318

0

针对不同的浏览器支持..

-webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover;