CSS Layout How to - Create two column layout with separator in between








Question

We would like to know how to create two column layout with separator in between.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.container {<!--   www.  ja va2 s.  c o  m-->
  border: 1px solid red;
  overflow: auto;
  margin: 10px 0;
}

.container .LC {
  width: 50%;
  margin: 0 -1em;
  float: left;
  background-color: yellow;
  border-right: 1em solid blue;
}

.container .RC {
  width: 50%;
  float: left;
  background-color: cyan;
  border-left: 1em solid blue;
}

</style>
</head>
<body>
  <div class="container">
    <div class="LC">Left</div>
    <div class="RC"> Right<br/></div>
  </div>
</body>
</html>

The code above is rendered as follows: