2017-01-03 72 views
1

我試圖找到解決方案,我在iOS設備上使用固定背景的問題。我寧願不必爲本網站重新設計所有內容,我希望有一些CSS更改可以解決它。 This就是這個網站在iPhones上的樣子,this就是它應該的樣子。我使用的CSS代碼如下:背景附件:固定不適用於iOS

.container { 
    min-width: 320px; 
    max-width: 480px; 
    margin: 0 auto; 
} 

.fixed-background { 
    height: 800px; 
    -webkit-backgound-size: cover; 
    -o-backgound-size: cover; 
    -moz-backgound-size: cover; 
    background-size: cover; 
    background-attachment: fixed; 
    background-repeat: no-repeat; 
    background-position: center center; 
    text-align: center; 
    overflow: auto; 
} 

我也使用@media查詢來修復它使用計算器上的一些帖子的iOS嘗試,但這似乎並沒有產生任何影響:

@media screen and (min-color-index:0) and (-webkit-min-device-pixel-ratio:0) { 
    .fixed-background { 
     background-attachment: scroll; 
    } 
} 

HTML

<div class="fixed-background bg-1"> 
    <div class="container"> 
     <div class="title"> 
      <h1>ROOK PROPERTY<br>MANAGEMENT INC.</h1> 
      <h2>CONDOMINIUM MANAGEMENT</h2> 
     </div> 
    </div> 
</div> 
+0

你有沒有試過這個 http://stackoverflow.com/questions/23236158/how-to-replicate-background-attachment-fixed-on-ios – Shashi

+0

經過一番辯論後,我結束了剛剛使用position:scroll for the mobile CSS。感謝您的信息。 –

+0

我認爲這回答你的問題:http://stackoverflow.com/questions/24154666/background-image-size-cover-not-working-on-ios/43058483#43058483 –

回答

4

我剛剛經歷了同樣的問題去了,這是我如何解決它。

首先,你需要聲明你的身體和HTML 100%寬,100%高大:

html, body{ 
 
\t width: 100%; 
 
\t height: 100%; 
 
}

然後,您的網頁上滾動不能由完成身體:你必須把它包裝在容器上。這個容器需要三個參數:overflow:scroll,width:100%,height:100%。我建議在包裹它的整個網站:

#wrapper{ 
 
\t \t width: 100%; 
 
\t \t height: 100%; 
 
\t \t overflow: scroll; 
 
\t }

如果你不喜歡它的滾動,你也可以嘗試加入 -webkit-溢出滾動:觸摸。

希望能幫助你/誰來找這個!

-1

我所有的分度,固定的背景我想補充類class="parallax iparaxify paraxify" 而在我的主css文件,我有:

.parallax { 
width: 100%; 
background url(../images/bg.jpg) no-repeat center center; 
-webkit-background-size: cover; 
-moz-background-size: cover; 
-o-background-size: cover; 
background-size: cover; 
} 

最後使其視差的一切,除了我的產品

.paraxify { 
    background-attachment: fixed; 
    background-position: center center; 
    background-size: cover; 
} 

在最後停用position:fixed爲ipad,iphone和ipod與jquery

​​