CSS Layout How to - Create two columns layout with absolute positioning








Question

We would like to know how to create two columns layout with absolute positioning.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#wrapper {<!--   w ww  .j  av  a 2  s.  c  o m-->
  width: 100%;
  height: 100px;
  border: 1px dotted gray;
  position: relative;
}

#left {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 200px;
  background-color: blue;
}

#right {
  position: absolute;
  left: 0;
  right: 210px;
  top: 0;
  bottom: 0;
  background-color: #5a71e5;
}
</style>
</head>
<body>
  <div id="wrapper">
    <div id="left"></div>
    <div id="right"></div>
  </div>
  <p>And more content can follow...</p>
</body>
</html>

The code above is rendered as follows: