HTML Element Style How to - Set column width of table in div with horizontal scrollbar








Question

We would like to know how to set column width of table in div with horizontal scrollbar.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#content {<!--from   w  w w  . j ava2  s  . c om-->
  width: 200px;
  overflow-x: auto;
}

td, th {
  border-style: solid;
}
</style>
</head>
<body>
  <div id="content">
    <table style="border-style: solid;">
      <tr>
        <th style="min-width: 50px">124</th>
        <th style="min-width: 550px">124</th>
      </tr>
      <tr>
        <td>124</td>
        <td>124</td>
      </tr>
    </table>
  </div>
</body>
</html>

The code above is rendered as follows: