How do I change the hover over color for a hover over table in Bootstrap?

前端 未结 11 1896
情歌与酒
情歌与酒 2021-01-30 02:58

I have a table with class \'table-hover\'. The default hover over color is a white / light grey. How do I change this color?

I\'ve tried overwriting the default by ad

相关标签:
11条回答
  • 2021-01-30 03:22
    .table-hover tbody tr:hover td {
        background: aqua;
    }
    

    this is the best solution i can gice so far.it works out perfectly in such scena

    0 讨论(0)
  • 2021-01-30 03:29

    HTML CODE:

    <table class="table table-hover">
        <thead>
            <tr>
                <th>Firstname</th>
                <th>Lastname</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>John</td>
                <td>Doe</td>
                <td>john@example.com</td>
            </tr>
            <tr>
                <td>Mary</td>
                <td>Moe</td>
                <td>mary@example.com</td>
            </tr>
            <tr>
                <td>July</td>
                <td>Dooley</td>
                <td>july@example.com</td>
            </tr>
        </tbody>
    

    CSS CODE

    .table-hover thead tr:hover th, .table-hover tbody tr:hover td {
        background-color: #D1D119;
    }
    

    The css code indicate that:

    mouse over row:

    .table-hover > thead > tr:hover

    background color of th will change to #D1D119

    th

    Same action will happen for tbody

    .table-hover tbody tr:hover td

    0 讨论(0)
  • 2021-01-30 03:29

    For me @pvskisteak5 answer has caused a "flicker-effect". To fix this, add the following:

                .table-hover tbody tr:hover,
                .table-hover tbody tr:hover td,
                .table-hover tbody tr:hover th{
                    background:#22313F !important;
                    color:#fff !important;
                }
    
    0 讨论(0)
  • 2021-01-30 03:31

    This is for bootstrap v4 compiled via grunt or some other task runner

    You would need to change $table-hover-bg to set the highlight on hover

    $table-cell-padding:            .75rem !default;
    $table-sm-cell-padding:         .3rem !default;
    
    $table-bg:                      transparent !default;
    $table-accent-bg:               rgba(0,0,0,.05) !default;
    $table-hover-bg:                rgba(0,0,0,.075) !default;
    $table-active-bg:               $table-hover-bg !default;
    
    $table-border-width:            $border-width !default;
    $table-border-color:            $gray-lighter !default;
    
    0 讨论(0)
  • 2021-01-30 03:38

    This worked for me:

    .table tbody tr:hover td, .table tbody tr:hover th {
        background-color: #eeeeea;
    }
    
    0 讨论(0)
提交回复
热议问题