2

I was trying a simple trick of changing hover color of a responsive table but failed.

I tried chaining the CSS but failed.

Do I need to add more CSS tags to make this happen.

Could you please help me to understand what is wrong in my approach.

Here is my code:

    <!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script>
.table-hover thead tr:hover th, .table-hover tbody tr:hover td {
    background-color: #FF0000;
}
  </script>
</head>
<body>

<div class="container">
  <h2>Table</h2>
  <p>The .table-hover class enables a hover state on table rows within a tbody:</p>

<table class="table table-hover">
    <thead>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>John</td>
            <td>Doe</td>
            <td>john@example.com</td>
        </tr>
        <tr>
            <td>Mary</td>
            <td>Moe</td>
            <td>mary@example.com</td>
        </tr>
        <tr>
            <td>July</td>
            <td>Dooley</td>
            <td>july@example.com</td>
        </tr>
    </tbody>

  </table>
</div>

</body>
</html>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

2
`<style>
 .table-hover thead tr:hover th, .table-hover tbody tr:hover td {
background-color: #FF0000;
 }
 </style>`

this code make highlight even over table header, this one make highlight only over table body

`<style>
 .table-hover tbody tr:hover td {
  background-color: #FF0000;
 }
 </style>`
1

You have to put style instead of script on the CSS

Here make it:

<style>
.table-hover thead tr:hover th, .table-hover tbody tr:hover td {
    background-color: #FF0000;
}
</style>
user8256287
  • 177
  • 15