且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使两列的高度相同,无论内容如何

更新时间:2022-10-19 12:59:42

如果您绝对必须避免使用TABLE,您可以将您的div风格设置为与

相同的表格

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

你可以看看markup / css,结果是这个小提琴:http://jsfiddle.net/aeinbu/QDBff/35/


I have a basic grid system, really basic, which puts to 'cells' side by side in a fluid 'row'. I want the two cells to always match their height so they are equal. So if one has more content than the other, the other expands to match the height of the cell with more content.

<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>

Demo of the problem here: http://jsfiddle.net/QDBff/

If you absolutly must avoid using TABLEs, you can style your divs to behave like tables with

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

You can look at the markup/css and results in this fiddle: http://jsfiddle.net/aeinbu/QDBff/35/