HTML Element Style How to - Create div based table with varying dimensions








Question

We would like to know how to create div based table with varying dimensions.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#main {<!--  w ww  .j  a v  a 2 s . co  m-->
  width: 50%;
  background: red;
  display: table;
  overflow: hidden;
}

#main>div {
  display: table-cell;
  text-align: center;
  background: yellow;
  box-sizing: border-box;
  border-right: 1px solid black;
}
</style>
</head>
<body>
  <div id="main">
    <div>1</div>
    <div>2</div>
    <div>
      3<br>3
    </div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
  </div>
</body>
</html>

The code above is rendered as follows: