HTML Element Style How to - Apply different style in table headers








Question

We would like to know how to apply different style in table headers.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.historystyle th {<!--from  ww  w  . jav a2  s  .  c o m-->
  border: 1px solid black;
  background: red;
  cursor: pointer;
}
.historystyle th:first-of-type {
  background: blue;
}
</style>
</head>
<body>
  <table class="historystyle">
    <tr>
      <th style="background-image: none">name</th>
      <th>location</th>
      <th>job</th>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: