Search code examples
htmlhoverhighlight

HTML table highlight row on hover except first row (header)


All,

I have an ASP.NET GridView that is rendered to an HTML table.

<table>
    <tr><th>Col 1 Head</th><th>Col 2 Head</th></tr>
    <tr><td>Data 1</td><td>Data 2</td></tr>
    <tr><td>Data 3</td><td>Data 4</td></tr>
</table>

I want to highlight the row when the mouse is hovered over it - except for the first row which is the header.

I am just getting my head wet with JQuery, and have dabbled a bit with CSS (either CSS2 or CSS3). Is there a preferred way to do this?

Can anyone give me a starting point for this?

Cheers

Andez


Solution

  • You can do this using the CSS :hover specifier. Here's a demonstration:

    <table>
        <tr><th>Col 1 Head</th><th>Col 2 Head</th></tr>
        <tr class = "notfirst"><td>Data 1</td><td>Data 2</td></tr>
        <tr class = "notfirst"><td>Data 3</td><td>Data 4</td></tr>
    </table>
    

    CSS:

    .notfirst:hover {
        background-color: red;
    }