tr:hover not working

后端 未结 13 1653
长发绾君心
长发绾君心 2020-12-08 09:27

I\'m trying to highlight (change background color) of the entire row when the mouse is hovering on a table row. I searched through the Net and it should be working, but it d

相关标签:
13条回答
  • 2020-12-08 09:39

    Works fine for me... The tr:hover should work. Probably it won't work because:

    1. The background color you have set is very light. You don't happen to use this on a white background, do you?

    2. Your <td> tags are not closed properly.

    Please note that hovering a <tr> will not work in older browsers.

    0 讨论(0)
  • 2020-12-08 09:39

    I had the same problem. I found that if I use a DOCTYPE like:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    

    it didn't work. But if I use:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    

    it did work.

    0 讨论(0)
  • 2020-12-08 09:42

    Try it:

    css code:

    .list1 tr:hover td {
        background-color:#fefefe;
    }
    
    0 讨论(0)
  • 2020-12-08 09:44

    Your best bet is to use

    table.YourClass tr:hover td {
    background-color: #FEFEFE;
    }
    

    Rows aren't fully support for background color but cells are, using the combination of :hover and the child element will yield the results you need.

    0 讨论(0)
  • 2020-12-08 09:46

    Like @wesley says, you have not closed your first <td>. You opened it two times.

    <table class="list1">
    <tr>
       <td>1</td><td>a</td>
    </tr>
    <tr>
       <td>2</td><td>b</td>
    </tr>
    <tr>
       <td>3</td><td>c</td>
    </tr>
    </table>
    

    CSS:

    .list1 tr:hover{
        background-color:#fefefe;
    }
    

    There is no JavaScript needed, just complete your HTML code

    0 讨论(0)
  • 2020-12-08 09:47

    Recently I had a similar problem, the problem was I was using background-color, use background: {anyColor}

    example:

    tr::hover td {background: red;}
    

    This works like charm!

    0 讨论(0)
提交回复
热议问题