2013-02-27 78 views
3

我有一個固定寬度爲960px的主包裝。在頂部和右側有一個登錄按鈕。通過按下此按鈕,它將直接在主包裝的正下方打開一個div層。因此我使用z-index:1.問題是我不知道如何根據主包裝器而不是瀏覽器窗口寬度設置固定位置。現在當設置左/右位置時,div將根據整個瀏覽器窗口的寬度進行放置。如果分辨率較高,則主包裝被置於0自動。如何放置z-index div?

來舉個例子:

代碼:

#main { 
    width:300px; 
    height: 500px; 
    background-color: #f23; 
    margin: 0 auto; 
} 
#zindex{ 
    font-size: 11px; 
    width: 50px; 
    height: 50px; 
    background-color: #dedede; 
    position: absolute; 
    right: 0;--> will place the div depending from the browser window and not main 
} 

example

,如果有一個人誰可以告訴我如何解決這個我真的感激。

回答

1
#main { 
    width:300px; 
    height: 500px; 
    background-color: #f23; 
    margin: 0 auto; 
    position: relative; 

} 

position:relative將使任何子元素將自己定位相對的是,代替body

還有的「位置」如何在barelyfitz.com

4
#main { 
    position:relative 
} 

應該這樣做。

1

工作過一些像樣的例子,你只需要給位置相對#main div的。例如:

#main { position: relative }