CSS Layout How to - Create two column layout with header and footer








Question

We would like to know how to create two column layout with header and footer.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
html, body {<!-- w  ww  .j  a  v a2  s .c  o  m-->
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: #ccc;
}

#header {
  background-color: #ccf;
}

#container {
  position: relative;
  min-height: 80%;
  border: 4px solid red;
  overflow: hidden;
}

#left {
  float: left;
  width: 200px;
  background-color: #cfc;
  padding-bottom: 9999px;
  margin-bottom: -9999px;
}

#main {
  position: relative;
  margin-left: 200px;
  background-color: #ffc;
  padding-bottom: 9999px;
  margin-bottom: -9999px;
}

#footer {
  background-color: #fcc;
}
</style>
</head>
<body>
  <div id="header">HEADER</div>
  <div id="container">
    <div id="left">LEFT</div>
    <div id="main">MAIN</div>
    <div style="clear: both"></div>
  </div>
  <div id="footer">FOOTER</div>
</body>
</html>

The code above is rendered as follows: