HTML Element Style How to - Style last cell on the table header with Last-child selector








Question

We would like to know how to style last cell on the table header with Last-child selector.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.bordered th {<!--   w w w  .ja  v a  2  s  .c o m-->
  border: 1px solid black;
}

.bordered th:last-child {
  border: 1px solid red;
}
</style>
</head>
<body>
  <table class="bordered" cellspacing="0" border="0" style="border-collapse: collapse;">
    <tr style="border-width: 0px;">
      <th scope="col">One</th>
      <th scope="col">Two</th>
      <th scope="col">Three</th>
      <th scope="col">four</th>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: