2012-01-17 131 views
2

我想要2個div。看着這樣的:CSS:重疊的DIV問題

的問題是,如果我只設置margin-top: -50px DIV2成爲在上面。 如果我使用z-index,DIV2會落後,但DIV2上的表單不能使用,因爲它DIV2稍微落後,不能被點擊,選擇或其中的任何一個。

如何讓它工作?

DIV1 CSS:

position:relative; 
height: 350px; 
margin-top: -50px; 
z-index: -10; 

DIV2 CSS:

padding: 24px; 
z-index: 10; 
margin-bottom: -50px; 
+1

請提供的css。 – dknaack

+0

也許你可以使用第三個透明的div,並給它最大的z-索引。比你把你的表格放在這個新的div裏。 –

回答

2

不知道任何細節,這可能與負z索引。

層疊順序使得區分正值和負值之間:

的規格定義7層畫的層。從後到前開始,他們 是:

The borders and background of the current stacking context 
Positioned descendants with negative z-index 
Nonpositioned block-level descendants with no z-index property defined -- paragraphs, tables, lists, and so on 
Floating descendants and their contents 
Nonpositioned inline content 
Positioned descendants with no z-index, z-index: auto, or z-index: 0 
Positioned descendants with z-index greater than 0 

來源是here

嘗試在DIV1積極的,而不是DIV2負

的z-index的

要精心打造的z-index,z-index的只適用於一個盒子疊水平,其位置值是絕對的,固定的,或相對的。

+0

我按照你的說法改正了,而不是有10和-10的z-index,我把它做成了10和5,但是佈局破了; \ – mgPePe

+0

小心,z-index只適用於一個盒子的堆疊層次,價值是絕對的,固定的或相對的。 – Wesley

+0

是的,那是我沒有意識到的問題。 – mgPePe

0

所以感謝韋斯利的幫助,下面是實際的代碼:

DIV1 CSS:

position:relative; 
z-index: 100; 

DIV2 CSS:

z-index: 10; 
margin-bottom: -50px;