2012-11-19 2 views
0

#stranger div를 #mother#child 사이에 넣으려면 어떻게해야하나요? 현재 #stranger div는 #mother#child을 모두 포함합니다.부모 div와 자식 사이에 div를 넣으려면 어떻게해야합니까?

<head> 
    <style> 
    #mother{ 
    position:absolute; 
    display:block; 
    width:300px; 
    height:300px; 
    background-color:green; 
    padding:40px; 
    z-index:1000; 
    } 
    #child{ 
    position:relative; 
    display:block; 
    width:180px; 
    height:180px; 
    background-color:yellow; 
    z-index:6000; 
    } 
    #stranger{ 
    position:relative; 
    display:block; 
    width:300px; 
    height:600px; 
    background-color:black; 
    z-index:1500; 
    } 
    </style> 
    </head> 
    <body> 
    <h1>Z-index Test</h1> 
    <h1>How Do I put #stranger between #mother and #child?</h1> 
    <div id='mother'> 
     <div id='child'></div> 
    </div> 
    <div id='stranger'></div> 
    </body> 
    </html> 
+1

소리가 너무 틀립니다. – BoltClock

+0

윤리적 인 양심의 가책이 없다면 나는 업보를합니다. – Emanegux

답변

2

#child가 #mother 내부에 중첩되어 있기 때문입니다. #mother가 #stranger보다 낮 으면 # 엄마의 #child도 낯선 사람보다 낮습니다. stacking context에 대한 설명을 참조하십시오.

당신은 내가 당신의 마크 업과 같이 있었다면 당신이 기대하는 생각 결과를 얻을 것입니다 :

<body> 
    <div id='mother'></div> 
    <div id='child'></div> 
    <div id='stranger'></div> 
</body> 

그런 다음 그들은 모두 같은 스택 문맥에있을 것입니다.

+0

thx,하지만 부모님과 아이조차도 b4 사이에 만들었다 고 생각했는데, 지금은 이상 할 수 없어요. 그래서 내가 엄마 div에 낯선 사람을두고 아이가된다면 너무 효과가 있습니다. – user1743251

관련 문제