【发布时间】:2023-03-09 09:50:01
【问题描述】:
我想做这样的布局:
http://i.stack.imgur.com/uhgMg.jpg
#container
{
width:600px;
background:blue;
margin:0 auto;
}
.box
{
float:left;
width:196px;
height:318px;
background:red;
}
#box1
{
position:relative;
left:-140px;
float:left;
}
#box2
{
position:relative;
left:-102px;
}
#box3
{
position:relative;
left:-66px;
}
#box4 //this div is doing the mess because it's default position is under the other 3 divs and that's why the container stretches.
{
position:relative;
left:558px;
top:-318px;
}
<div id="container">
<div>RANDOM CONTENT</div>
<div class="box" id="box1"></div>
<div class="box" id="box2"></div>
<div class="box" id="box3"></div>
<div class="box" id="box4"></div>
<div style="clear:both"></div>
</div>
在某个容器中有 4 个彼此相邻的相对定位 div。
我图片中的红线显示了容器的高度应该在哪里结束,但它不是因为最后一个 div 的默认位置在那里。由于上面的随机内容,我无法为容器设置固定高度。
怎么做?
【问题讨论】:
标签: css height css-position