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 }
2

2 Answers 2

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>

3
  • @David, I've updated the code above. Let me know if that helps.
    – Michael
    Aug 28, 2011 at 10:03
  • Can you post your code here so I can take a look. Here is my full code, try this pastebin.com/hY9GGJKG
    – Michael
    Aug 28, 2011 at 10:05
  • There were my mistakes in first try. your code works perfectly! Thanks!
    – David
    Aug 28, 2011 at 10:11
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 ???

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.