HTML Element Style How to - Make width of a table depend on the td's width








Question

We would like to know how to make width of a table depend on the td's width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
td.wide {<!--from  w ww.java  2 s.  c o  m-->
  width: 2000px;
  min-width: 2000px;
}
</style>
</head>
<body>
  <table border="1">
    <tr>
      <td width="200">left menus (200px)</td>
      <td>
        <table border="1" class="table-fixed" style="background-color: #ddd">
          <tr>
            <td class="wide" width="2000">2000px</td>
            <td class="wide" width="2000">2000px</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: