Changing background colour of tr element on mouseover

前端 未结 9 1014
一向
一向 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!! :)

提交回复
热议问题