HTML Element Style How to - Referencing Table elements








Question

We would like to know how to referencing Table elements.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
table {<!--  w w  w  .j a  v a  2s . c om-->
  border: 1px solid black;
}

table tr:nth-child(2) td:first-child {
  color: red;
}
</style>
</head>
<body>
  <table>
    <tr>
      <td>row 1 cell 1</td>
      <td>row 1 cell 2</td>
    </tr>
    <tr>
      <td>row 2 cell 1</td>
      <td>row 2 cell 2</td>
      <td>row 2 cell 3</td>
      <td>row 2 cell 4</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: