html - 无论内容如何,​​使两列高度相同

标签 html css

我有一个基本的网格系统,非常基本,它将“单元格”并排放置在一个流畅的“行”中。我希望这两个单元格始终匹配它们的高度,以便它们相等。因此,如果一个内容比另一个多,则另一个会扩展以匹配包含更多内容的单元格的高度。

<div class="row">
    <div class="cell1">
        <div class="inner">
            <h2>Cell 1</h2>
            <p>Regardless of content, can I make Cell 1 and Cell 2 the same height so the borders are level?</p>            
        </div>
    </div>
    <div class="cell2">
        <div class="inner">
            <h2>Cell 2</h2>
        </div>
    </div>
</div>

这里的问题演示:http://jsfiddle.net/QDBff/

最佳答案

如果您绝对必须避免使用 TABLE,您可以将您的 div 设置为表现得像表格一样

display: table;
display: table-row;
display: table-cell;

您可以查看此 fiddle 中的标记/CSS 和结果:http://jsfiddle.net/aeinbu/QDBff/35/

关于html - 无论内容如何,​​使两列高度相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16584959/

相关文章:

jquery - 将最小宽度应用于 Bootstrap 列有问题

javascript - 主选项卡需要仅使用 html、css 和 javascript 嵌套的子选项卡

javascript - 当绝对定位元素在浏览器窗口之外时扩展 "body"

css - 为什么 float 会导致顶部 margin 增加?

javascript - div 出现一秒钟然后再次隐藏?

html - 使 flex 元素采用内容宽度,而不是父容器的宽度

html - 将背景图像放在嵌入 html 邮件中的 <table> <td> <tr> 边框之外

javascript - 在滚动条上更改 div 的背景颜色

html - 我的 header 包含在我的主标记中

html - FontAwesome 从 4 升级到 5 (Tumblr)