Return to Snippet

Revision: 18184
at September 23, 2009 15:37 by paulgrenwood


Initial Code
// HTML

<div class="equal">
	<div class="row">
		<div class="one">

			<h2>This is a box</h2>
			<p>This box has less content than the one next to it, but both boxes will still have equal height. No background-image trickery.</p>
		</div>
		<div class="two">
        	<h2>This is another box</h2>
			<p>This box has more content than the others. If all boxes were table cells, the cell with the most content would decide the height of all cells. It works like that here too, but this is not a table.</p>
			<p>Instead, display:table, display:table-row and display:table-cell are used to make divs behave like table cells. Excellent. Too bad it doesn&rsquo;t work in you-know-which-browser. It does, however, work in modern browsers like Mozilla, Opera, Safari, Firefox, OmniWeb, Camino, and Netscape.</p>

			<p>Read the related blog entry for more info: <a href="/archive/200405/equal_height_boxes_with_css/">Equal height boxes with CSS</a>.</p>
		</div>
		<div class="three">
			<p>This box has even less content. Anything in it is vertically centered.</p>
		</div>
	</div>
</div>


// CSS

/* Layout rules */
	.equal {
		display:table;
		border-collapse:separate;
	}
	.row {
		display:table-row;
	}
	.row div {
		display:table-cell;
	}
	
	/* Styling rules to make the example look nicer */
	html,body {
		margin:0;
		padding:0;
		color:#000;
		background:#fff;
	}
	body {
		font:76%/140% "Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif;
	}
	.equal {
		margin:10px auto;
		border-spacing:10px;
		background:#898B60;
		width:80%;
	}
	.row div {
		background:#fff;
	}
	.row div.one {
		width:40%;
	}
	.row div.two {
		width:40%;
	}
	.row div.three {
		vertical-align:middle;
	}
	.row div h2 {
		margin:0 0 0.5em 0;
		padding:0.5em 10px;
		font-size:1.2em;
		color:#fff;
		background:#595B30;
	}
	.row div p {
		font-size:0.94em;
		margin:0.5em 0;
		padding:0 10px;
	}
	#labfooter {
		text-align:center;
	}

Initial URL


Initial Description


Initial Title
Equal Height Columns

Initial Tags
css

Initial Language
CSS