HTML Element Style How to - Space cells in DIV table








Question

We would like to know how to space cells in DIV table.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.container {<!--from  w ww  .  j a  v a2 s .com-->
  display: table;
  width: 100%;
  height: 100px;
  border-spacing: 5px;
}

.all {
  display: table-cell;
  border: 1px solid #333;
}

.left {
  width: 45px;
}

.right {
  width: 45px;
}

.center {
  width: auto;
  display: block;
  margin: 0 10px 0 10px;
  border: 1px solid red;
  height: inherit;
}
</style>
</head>
<body>
  <div class="container">
    <div class="all left">Left1</div>
    <div class="all left">Left2</div>
    <div class="all center">Center</div>
    <div class="all right">Right1</div>
    <div class="all right">Right2</div>
  </div>
</body>
</html>

The code above is rendered as follows: