【发布时间】:2013-03-16 14:24:57
【问题描述】:
我有一张带有“table-hover”类的表格。默认悬停在颜色上的是白色/浅灰色。如何更改此颜色?
我尝试通过将以下内容添加到我的主要样式表中来覆盖默认值
.table-hover tbody tr:hover > th {
background-color: #D1D119;
}
很遗憾,上述方法不起作用
【问题讨论】:
我有一张带有“table-hover”类的表格。默认悬停在颜色上的是白色/浅灰色。如何更改此颜色?
我尝试通过将以下内容添加到我的主要样式表中来覆盖默认值
.table-hover tbody tr:hover > th {
background-color: #D1D119;
}
很遗憾,上述方法不起作用
【问题讨论】:
试试这个:
.table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
background-color: #color;
}
【讨论】:
td? (对不起,我在 css 上一文不值,努力学习)
background-color: #color!important;
这是 imo 最简单的方法,它对我有用。
.table-hover tbody tr:hover td {
background: aqua;
}
不确定为什么要将标题颜色更改为与行相同的悬停颜色,但如果这样做,则可以使用上述解决方案。如果你只是想要 t
【讨论】:
这对我有用:
.table tbody tr:hover td, .table tbody tr:hover th {
background-color: #eeeeea;
}
【讨论】:
这适用于通过 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;
【讨论】:
$table-hover-bg, $table-active-bg 等等,而不是 $table-bg-...。以为我要疯了一分钟?
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>
CSS 代码
.table-hover thead tr:hover th, .table-hover tbody tr:hover td {
background-color: #D1D119;
}
css代码表明:
鼠标悬停在行上:
.table-hover > thead > tr:hover
th 的背景颜色将变为#D1D119
第
tbody 也会发生同样的动作
.table-hover tbody tr:hover td
【讨论】:
.table-hover tbody tr:hover td {
background: #ffffff;
}
【讨论】:
尝试:
.table-hover > tbody > tr.active:hover > th {
background-color: #color;
}
【讨论】:
对我来说,@pvskisteak5 的回答引起了“闪烁效应”。要解决此问题,请添加以下内容:
.table-hover tbody tr:hover,
.table-hover tbody tr:hover td,
.table-hover tbody tr:hover th{
background:#22313F !important;
color:#fff !important;
}
【讨论】:
.table-hover tbody tr:hover td {
background: aqua;
}
这是迄今为止我能想到的最好的解决方案。在这样的场景中效果很好
【讨论】:
我发现我必须覆盖引导程序使用的名为bs-table-accent-bg...的“CSS 自定义属性”...
.table-hover > tbody > tr:hover { --bs-table-accent-bg: #f8f8f8; }
路径是引导程序本身使用的。我是通过检查页面得出的。
因为如果我按照其他解决方案的做法进行操作,我无法使突出显示变得比已应用的引导程序更轻。这样,它就可以工作(即我可以让悬停颜色变浅)。
【讨论】:
不要更改默认的 table-hover 类,而是创建一个新类 ( anotherhover ) 并将其应用于您需要此效果的表。
代码如下;
.anotherhover tbody tr:hover td { background: CornflowerBlue; }
【讨论】:
您可以通过多种方式做到这一点,
// Your variable overrides
$table-hover-bg: #d00; // what's that you need
$table-striped-bg: #fff;
// Bootstrap and its default variables
@import "node_modules/bootstrap/scss/bootstrap";
.table {
--bs-table-hover-bg: #d00;
}
或
#thetable tr:hover, #thetable tr td:hover {
background-color: #d00;
}
【讨论】:
尝试Bootstrap的.table-hover类实现hoverable rows,例如
<table class="table table-hover">
...
</table>
【讨论】: