CSS Layout How to - Create two column layout with separator in between with total width less than 100%








Question

We would like to know how to create two column layout with separator in between with total width less than 100%.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.container {<!--from  w w  w .j a  v a2  s  .co  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;
}
.small {
  width: 60%;
  margin: 10px auto;
}
</style>
</head>
<body>
  <div class="container small">
    <div class="LC">Left</div>
    <div class="RC">Right</div>
  </div>
</body>
</html>

The code above is rendered as follows: