我想放置 3 个 div,如照片所示 div 编号 2 必须贴在底部
这是我所做的:http: //jsfiddle.net/GLHur/1/
尝试这个:
<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; }
这有效:
#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;}
我建议您使用绝对位置进行此基本定位:
<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; }
<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>
通过使外部 div “相对”,您可以使用绝对比例将其他 div 定位在内部。将第二个对齐到右侧,最后一个对齐到右侧和底部。您可能需要根据需要为样式添加高度/最小高度。