【发布时间】:2015-07-22 21:51:01
【问题描述】:
好的,所以我知道使用table 进行布局是非常过时的。但是我需要使用两个并排的元素进行布局,一个具有通常的高度,如果它具有更高的内容,则可以增加,另一个包含图像。如果第一个长得更高,我希望有图像的那个长到与它的高度相匹配。
这是我可以通过良好的旧 table 轻松实现的目标。如何使用 div 做到这一点?
这是我想要做的:
.body {
width: 748px;
margin: 20px auto;
}
.breaker {
margin: 20px 0;
outline: 1px solid purple;
}
.poll {
background: pink;
width: 248px;
height: 250px;
}
div.poll {
float: left;
}
.story {
float: right;
width: 500px;
background-size: cover;
}
<div class="body">
<table class="breaker">
<tr>
<!-- This will have a variable height depending on content -->
<td class="poll"></td>
<!-- The height of this should match the height of .poll -->
<td style="width:500px;background-image:url(http://lorempixel.com/output/animals-q-c-600-200-1.jpg);background-size:cover;">
</td>
</tr>
</table>
<div class="breaker">
<!-- This will have a variable height depending on content -->
<div class="poll"></div>
<!-- The height of this should match the height of .poll -->
<div class="story" style="background-image:url(http://lorempixel.com/output/animals-q-c-600-200-1.jpg)">
</div>
</div>
</div>
【问题讨论】:
-
等高是
布局或 CSS 表格布局的原生特性之一,请参阅这个简化的演示 - jsfiddle.net/LLy1sLhq
标签: html css tablelayout