Changing background colour of tr element on mouseover

前端 未结 9 890
一向
一向 2021-02-01 13:00

I want to have my table rows highlighted on mouse over, but I have yet to find a way to do it that isn\'t using Javascript. Is this not possible in CSS?

I\'ve tried this

相关标签:
9条回答
  • 2021-02-01 13:49

    I had the same problem:

    tr:hover { background: #000 !important; }
    

    allone did not work, but adding

    tr:hover td { background: transparent; }
    

    to the next line of my css did the job for me!! My problem was that some of the TDs already had a background-color assigned and I did not know that I have to set that to TRANSPARENT to make the tr:hover work.

    Actually, I used it with a classnames:

    .trclass:hover { background: #000 !important; }
    .trclass:hover td { background: transparent; }
    

    Thanks for these answers, they made my day!! :)

    0 讨论(0)
  • 2021-02-01 13:49
    tr:hover td.someclass {
       background: #EDB01C;
       color:#FFF;
    }
    

    only someclass cell highlight

    0 讨论(0)
  • 2021-02-01 13:50

    <tr>s themselves are very hard to access with CSS, try tr:hover td {background:#000}

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