How to highlight the table row on mouse hover

后端 未结 3 574
说谎
说谎 2021-01-06 14:50

I have this table:

相关标签:
3条回答
  • 2021-01-06 15:06

    HTML:

    <table class="table-hover">
    

    CSS:

    .table-hover > tbody > tr:hover {
        background-color: #f5f5f5;
    }
    

    And if else you want is to make the tr selectable:

    HTML:

    <tr ng-click="doSomething()">
    

    CSS:

    tr[ng-click] {
        cursor: pointer;
    }
    

    View JSFiddle Sample

    0 讨论(0)
  • 2021-01-06 15:08

    I'm not familiar with Angular, so this may be the incorrect way to do this, but this seems to work on your fiddle ...

    change the row to

    <tr ng-class="rollClass" ng-repeat="roll in sushi | orderBy:sortType:sortReverse | filter:searchFish" ng-mouseenter="rollClass = 'highlight'" ng-mouseleave="rollClass = ''">
    

    and add the css class

    .highlight {
        background-color: gray;
    }
    

    The idea comes from this SO question

    0 讨论(0)
  • 2021-01-06 15:19

    you can apply class on mouse over like this.

    http://jsfiddle.net/uuws8hbv/

    <tr ng-repeat="roll in sushi | orderBy:sortType:sortReverse | filter:searchFish track by $index" ng-mouseover="rowselected($index)" 
      ng-class="{selected : $index == rowNumber}"
    

    in the controller add function.

    $scope.rowselected = function(row)
    {
       $scope.rowNumber = row;
    }
    
    0 讨论(0)
提交回复
热议问题