2

I have a table that has a class, and some td elements inside of it. What is the correct CSS to give a hover effect on tds which are part of a table with some particular class?

<table class='some_class'>
    <tr>
        <td>123</td>
        <td>321</td>
    </tr>
</table>

What's the right CSS? This is not working:

> .some_class td:hover { some style }
Sam Starling
  • 5,298
  • 3
  • 35
  • 52
David
  • 4,332
  • 13
  • 54
  • 93

2 Answers2

4

put this in your css file

body {
background-color: #ccc;
}

table.some_style td {
background-color: #0f0;
}

table.some_style td:hover {
background-color: #06c;
}

and this as your table

<table class="some_style">
<thead>
    <tr>
        <th>column one</th>
                    <th>column two</th>
                                <th>column three</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>data one</td>
                    <td>data two</td>
                                <td>data three</td>
    </tr>
</tbody>

Michael
  • 4,282
  • 9
  • 55
  • 89
0

This is working for me table td:hover{ background : red; }

<table class='some_class'>
<tr>   
<td>123</td>
<td>321</td>
</tr>
</table>

I think your code should work also, maybe you didn't include css correctly , which browser do you use ???

Mina Kolta
  • 1,551
  • 2
  • 12
  • 22