2012-07-22 73 views
3

我希望我的背景DIV能夠隨時填充整個瀏覽器窗口。我在背景的頂部有一個DIV,它以我想要的方式移動,我有按百分比設置的定位。當我縮小時,兩個DIV一起移動,創建背景顏色的曝光。這裏是我的地盤:即使使用縮放也能填充瀏覽器窗口的DIV

http://search.officesupplycentral.org/details.html

這裏是我怎麼想我的DIV發揮作用的例子:

http://fab.com/

任何幫助將不勝感激!

吉姆

+0

你嘗試把身體的「背景圖像」屬性? V – vellvisher 2012-07-23 07:02:44

+0

放入正文。 background:url('image.jpg')fixed; background-size:100%; – kakarott 2012-08-08 06:17:46

回答

0

fab.com使用一種特殊的做法,很容易看到,如果你只是檢查站點的代碼。

它設置背景的HTML標籤<html style="background-image: url(//s3.amazonaws.com/static.fab.com/relaunch/fab-daily-design-for-everyone-8.jpg);">並設置以下值,它在CSS文件:

html{ 
    background-repeat: no-repeat; 
    background-attachment: fixed; 
    background-position: center center; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
} 

它然後設置背景<body>透明的CSS:

body{ 
    background: transparent; 
} 

我的教育猜測沒有進一步研究這一點,因爲圖像被設置爲<html>標記的背景,並且背景大小設置爲覆蓋,所以在頁面放大或縮小時不處理它。