HTML Element Style How to - Set td in table cell width / height and background








Question

We would like to know how to set td in table cell width / height and background.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
td {<!-- w ww .  ja va 2s.  c o m-->
  width: 200px;
  height: 300px;
  background: url('http://www.java2s.com/style/download.png');
}

table {
  border-collapse: collapse;
}
</style>
</head>
<body>
  <table>
    <tr>
      <td>a</td>
      <td>b</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: