HTML Element Style How to - Layout UL as table








Question

We would like to know how to layout UL as table.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
ul {<!-- ww w.j  a  va  2 s. co  m-->
  display: table;
  table-layout: fixed;
  width: 100%;
  border: 1px solid #c2c2c2;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

li {
  text-align: center;
  display: table-cell;
  border-right: 1px solid #c2c2c2;
}

li:last-child {
  border: none; /* no right border on last li */
}
</style>
</head>
<body>
  <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
    <li>Item5</li>
  </ul>
</body>
</html>

The code above is rendered as follows: