所有内容都是动态的。
#block {
width: 500px;
background-color:#fff000;
border: thin solid #999;
}
#col1{
width: 300px;
background-color:#ffffff;
float:left;
height:auto;
overflow: auto;
}
#col2{
width: 180px;
background-color:#ffaaff;
float:right;
}
.clear {
clear: both
}
<div id="block">
<div id="col1">
white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white
</div>
<div id="col2">
pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink
</div>
<div class="clear"></div>
</div>
我希望白色柱垂直拉伸以匹配粉色柱的高度(到达底部黄色边框)。我不喜欢使用绝对或相对显示。
这是 和 的解决display:relative
方案display:absolute
。它有效,但在更复杂的结构中给我带来了其他问题。
#block {
width: 500px;
background-color:#fff000;
border: thin solid #999;
position:relative;
}
#col1{
width: 300px;
background-color:#ffffff;
float:left;
height:100%;
overflow: auto;
position:absolute;
}
#col2{
width: 180px;
background-color:#ffaaff;
float:right;
}
.clear {
clear: both
}
<div id="block">
<div id="col1">
white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white white
</div>
<div id="col2">
pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink pink
</div>
<div class="clear"></div>
</div>