2015-10-09 21 views
0

任何人都可以告訴我這種效果是如何創建的嗎?一個頁面上有多個Z-index元素

Link to desired effect

從而使標題欄和形象留靜態的,但是當你向下滾動網頁上的內容區域重疊的圖像,但沒有頭。

我認爲也許標題和bg圖像和內容區域都有不同的z-index,但我似乎不能複製這種效果。

下面是我一直與玩弄本地:

<style type="text/css"> 

body{ 
    margin:0px; 
    padding:0px; 
} 
#head{ 
    width:2000px; 
    height:180px; 
    background-color:#666; 
    position: fixed; 
    z-index: 10000; 
} 

#image{ 
    width:2000px; 
    height:500px; 
    background-color:#F00; 
} 

#content{ 
    width:2000px; 
    height:1000px; 
    background-color:#090; 
} 
</style> 

<div id="head">HEAD</div> 
<div id="image">IMAGE</div> 
<div id="content">CONTENT</div> 
+2

'inspect element'並試一試 –

+0

是它的視差設計? – Arun

+0

它被稱爲視差設計 –

回答

1

定身(或包裹元素)有一個背景:

body { 
    background-attachment: fixed; 
} 

更多:http://www.w3schools.com/cssref/pr_background-attachment.asp

這迫使背景保持放置狀態,即使使用頁面滾動。

然後將您的內容添加到正文中... 它將滾動,而身體的背景是靜態的。

例:https://jsfiddle.net/a8qpxzy2/2/

+0

是的..這是它!謝謝。 – Pogostick

+0

當然!請幫助我並選擇它作爲正確的答案! @Pogostick – johnchinjew

+0

更多關於'視差'這裏:http://keithclark.co.uk/articles/pure-css-parallax-websites @Pogostick – johnchinjew

0

這裏是他們是如何做到的。

headerbg-image都是固定的。而content設置爲relative

Headers的z-index爲10000,bg-image的z-index爲20和content的z-index是2000

你應該知道它是如何工作的這些信息。

相關問題