2013-09-22 61 views
1

在我正在處理的網站上我有一個背景圖片,我想填充100%寬度&瀏覽器的高度爲100%&需要修復..下面的代碼適用於ie10 & firefox 23,但不適用於Chrome (背景不固定 - 它滾動)。如何讓我的背景在Chrome中得到修復?

現場演示:http://ridge.mydevelopmentserver.com/

<div id="mainContent" class="bg1">my content</div> 

#mainContent { 
height: auto; 
-webkit-background-size: cover; 
-moz-background-size: cover; 
-o-background-size: cover; 
background-size: cover; 
color:#777777; 
padding:20px; 
box-sizing: border-box; 
} 

.bg1 { 
background:url(../images/backgrounds/bg1.jpg) no-repeat center center fixed; 
} 

任何人都知道如何使固定在Chrome的背景是什麼?

謝謝:)

+0

通過使用一般的'background'財產,要覆蓋,你不與他們的默認給出一個明確的價值的所有屬性 - 看起來像瀏覽器的背景size'是否'由包括不同一般'背景'或不。嘗試給'.bg1'單獨設置的屬性('background-url','background-repeat',...),或者移動一些你不想改變的「普通」屬性,直到'#mainContent'。 – CBroe

回答

2

加固定的左,上,右,下零.bg1位置,不要忘記溢出-Y:滾動;

.bg1 { 
    position: fixed; 
    left: 0; 
    top: 0; 
    bottom: 0; 
    right: 0; 
    background: url(../images/backgrounds/bg1.jpg); 
    background-position: center center; 
    background-repeat: no-repeat; 
    background-attachment: fixed; 
    overflow-y: scroll; 
    } 
+0

我將溢出更改爲「overflow:auto;」所以它滾動兩種方式(如果滾動是必需的),這很好 - 謝謝! – MWD