2012-08-03 66 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