HTML Element Style How to - Create table with div using display: table;








Question

We would like to know how to create table with div using display: table;.

Answer


<!DOCTYPE html>
<html>
<body>
  <div style="display: table; width: 100%;">
    <div style="display: table-cell; width: 25%; background: green;">
      One<br /> One<br /> One<br /> One<br /> One<br /> One<br /> One<br />
      One<br /> One<br /> One<br /> One
    </div><!--from   w  w w .  j ava 2s. co m-->
    <div style="display: table-cell; width: 25%; background: blue;">
      Two</div>
    <div style="display: table-cell; width: 25%; background: navy;">
      Three</div>
    <div style="display: table-cell; width: 25%; background: red;">
      Four</div>
  </div>
  <div style="background: blue">Bottom</div>
</body>
</html>

The code above is rendered as follows: