2013-10-04 24 views
3

是否有可能將子女(C)放在其父母(B)之下,以及B的鄰居(C)之下?在其父母下的CSS職位的子女

這有點難以描述,你可以看例子here

問題是將藍色div.inner定位在紅色div.neighbor以上並且綠色div.outer下。

爲了說明:

enter image description here

HTML代碼:

<div class="neighbor">&nbsp;</div> 
<div class="outer"> 
    <div class="inner"></div> 
</div> 

CSS代碼:

.neighbor{ 
background-color: red; 
height: 500px; 
width: 500px;  
} 

.outer{ 
background-color: green; 
width: 300px; 
height: 300px; 
position: fixed; 
top: 0px; 
left: 0px;  
} 

.inner{ 
background-color: blue; 
width: 100px; 
height: 100px; 
position: fixed; 
top: 0px; 
left:250px;  
} 
+0

你能provied的圖像,顯​​示你正在試圖達到什麼? – idmean

+0

要定位藍色div上方紅色和綠色下http://tinypic.com/r/2drbfk0/5 –

+0

這是你想要的嗎? [小提琴](http://jsfiddle.net/PHPzF/3/)。 –

回答

3

JsFiddle

HTML:

<div class="red"></div> 
<div class="green"></div> 
<div class="blue"></div> 

CSS:

.red { 
    background-color: red; 
    height: 500px; 
    width: 500px; 
    z-index: 1; 
} 

.green { 
    background-color: green; 
    width: 300px; 
    height: 300px; 
    position: fixed; 
    top: 0px; 
    left: 0px; 
    z-index: 3; 
} 

.blue { 
    background-color: blue; 
    width: 100px; 
    height: 100px; 
    position: fixed; 
    top: 0px; 
    left: 250px; 
    z-index: 2; 
} 
+0

你假設他想要一個固定的位置值,但並非總是如此! –

0
.neighboor { 
     background-color: red; 
     height: 500px; 
     width: 500px; 
     position:fixed; 
     z-index:-200; 
    } 

    .outer { 
     background-color: green; 
     width: 300px; 
     height: 300px; 
     position: absolute; 
     top: 0px; 
     left: 0px; 
    } 

    .inner { 
     background-color: blue; 
     width: 100px; 
     height: 100px; 
     position:relative; 
     z-index: -100; 
     top: 0px; 
     left: 250px; 
    }