HTML Element Style How to - Force TD width when table width is 100%








Question

We would like to know how to force TD width when table width is 100%.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#mytable td {<!--  w w  w .j av a2  s  .  c om-->
  width: 50px;
  background: green
}
</style>
</head>
<body>
  <table id="mytable" style="width: 100%; background: red">
    <tr>
      <td>TEXT1</td>
      <td>TEXT2</td>
      <td style="width: 100%; background: blue">&nbsp;</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: