2013-08-06 82 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;