CSS Layout How to - Match the height of both column in a two column layout








Question

We would like to know how to match the height of both column in a two column layout.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.wrapper {<!-- ww  w .j  ava  2 s. c  o m-->
  height: 100%;
  width: 100%;
  display: table;
  float: left;
}

.content {
  border: 1px solid red;
  margin: 5em 0 0;
  padding: 1em;
  height: 100%;
  background: red; /* for test */
  display: table-cell;
}

.sidebar {
  border: 1px solid blue;
  margin: 5em -0.1em 0;
  padding: 1em;
  height: 100%;
  background: #EEE; /* for test */
  display: table-cell;
}
</style>
</head>
<body>
  <div id="#wrapper">
    <div class="content">asdf</div>
    <div class="sidebar">
      asdf<br>asdf<br>asdf
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: