如何将鼠标悬停在颜色上以悬停在Bootstrap中的表格上?

Llo*_*nks 100 twitter-bootstrap

我有一个表'table-hover'的表.默认悬停在颜色上的是白色/浅灰色.我该如何改变这种颜色?

我已经尝试通过在我的主导样式表中添加以下内容来覆盖默认值

.table-hover tbody tr:hover > th {
  background-color: #D1D119;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,上述方法无效

pvs*_*ak5 218

尝试一下:

.table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
  background-color: #color;
}
Run Code Online (Sandbox Code Playgroud)

  • @AlexanderDerck我想这可能有点晚了,但是td是必需的,因为它从它的行进一步向下dom,如果有一个背景已经应用到td,那么你将看不到行的背景,因为它'将在行后绘制. (6认同)
  • 为什么需要`td`?(抱歉,我在css上毫无价值,试图学习) (4认同)

小智 15

这是imo最简单的方法,它对我有用.

.table-hover tbody tr:hover td {
    background: aqua;
}
Run Code Online (Sandbox Code Playgroud)

不确定为什么要将标题颜色更改为与行相同的悬停颜色,但如果这样做,则可以使用上述解决方案.如果你只是想要


小智 13

这对我有用:

.table tbody tr:hover td, .table tbody tr:hover th {
    background-color: #eeeeea;
}
Run Code Online (Sandbox Code Playgroud)


sty*_*yks 6

这是用于通过 grunt 或其他一些任务运行程序编译的 bootstrap v4

您需要更改$table-hover-bg以设置悬停时的突出显示

$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;
Run Code Online (Sandbox Code Playgroud)


Tan*_*man 5

HTML代码

<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>
Run Code Online (Sandbox Code Playgroud)

代码

<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>
Run Code Online (Sandbox Code Playgroud)

css代码表明:

鼠标悬停在行上:

.table-hover > thead > tr:hover

th 的背景颜色将更改为 #D1D119

tbody 也会发生同样的动作

.table-hover tbody tr:hover td