2012-08-03 64 views
5

enter image description here放置一個div未來兩個div對方

我要放置3周的div所示上面的照片 格2號必須堅持底部

這裏是我做了什麼: http://jsfiddle.net/GLHur/1/

+0

由於我的CSS技巧是絕對的垃圾,我不打算張貼此作爲一個答案。我要發佈這個作爲如何做不到:http://jsfiddle.net/GLHur/4/雖然仍然工作! – rsplak 2012-08-03 13:44:40

+0

@rsplak你的回答是對的,但是op在評論中提到他不想使用固定的利潤率 – Prashobh 2012-08-03 13:54:15

回答

2

這工作:

#div3{height:100px;width:100px;border: solid 1px #000; 
display:inline-block;} 
    #div1{height:30px;width:100px;border: solid 1px #000;} 
#div2{height:20px;width:100px;border: solid 1px #000; position: absolute; bottom: 0} 
#div1_2{display:inline-block;vertical-align:top; position: relative; height: 100px;} 
+0

http://jsfiddle.net/GLHur/20/ – 2012-08-03 14:01:31

1

是這樣的嗎?

http://jsfiddle.net/GLHur/6/


抑或是高度的變化,一旦你添加的內容?

+0

div2的高度有時候不同,這就是爲什麼我不能使用固定利潤率 – 2012-08-03 13:46:34

4

試試這個:

http://jsfiddle.net/GLHur/18/

<div class="con"> 
    <div id="div3"></div> 
    <div id="div1_2"> 
     <div id="div1"></div> 
     <div id="div2"></div> 
    </div> 
</div> 

#div3{height:100px;width:100px;border: solid 1px #000; display:inline-block; background:red;} 

#div1{height:30px;width:100px;border: solid 1px #000; position:absolute; top:0; background:blue;} 
#div2{height:20px;width:100px;border: solid 1px #000; position:absolute; bottom:0; background:green;} 

#div1_2{display:inline-block; vertical-align:top;} 


.con { position:relative; }​ 
0
<div style="position: relative;"> 
    <div style="height: 100%;"> </div> 
    <div style="position: absolute; right: 0px;"> </div> 
    <div style="position: absolute; right: 0px; bottom: 0px;"> </div> 
</div> 

通過使內部使用絕對規模外格 '相對',你可以放置其他的申報單。將第二個調整到右側,最後一個調整到右側和底部。您可能需要根據需要爲樣式添加高度/最小高度。

1

我建議你塗使用絕對位置這一基本positionning:

<div id="content"> 
    <div id="div3"></div> 
    <div id="div1"></div> 
    <div id="div2"></div> 
</div> 

#content { position: relative; height: 100px; width: 220px; } 

#div1{ position: absolute; top: 0; right: 0; height:30px; width:100px; background: blue; } 
#div2{ position: absolute; bottom:0; right: 0; height:20px; width:100px; background: green; } 
#div3{ position: absolute; top: 0; left: 0; height:100px; width:100px; background: red; } 

jsFiddle