我有一张带有“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;
}
这是imo最简单的方法,它对我有用。
.table-hover tbody tr:hover td {
background: aqua;
}
不知道为什么要将标题颜色更改为与行相同的悬停颜色,但如果这样做,则可以使用上述解决方案。如果你只是想要
这对我有用:
.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;
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
th
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;
}
我发现我必须覆盖引导程序使用的“CSS 自定义属性”,该属性称为bs-table-accent-bg
...
.table-hover > tbody > tr:hover { --bs-table-accent-bg: #f8f8f8; }
路径是引导程序本身使用的。我是从检查页面中得出的。
因为如果我做了其他解决方案所做的事情,我无法让突出显示变得比已经应用的引导程序更轻。这样,它就可以工作(即我可以让悬停颜色变浅)。
.table-hover tbody tr:hover td {
background: aqua;
}
这是迄今为止我能想到的最好的解决方案。它在这样的场景中完美运行
您可以通过多种方式做到这一点,
// 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;
}
不要更改默认的 table-hover 类,而是创建一个新类( anotherhover )并将其应用于您需要此效果的表。
代码如下;
.anotherhover tbody tr:hover td { background: CornflowerBlue; }
例如,尝试使用 Bootstrap 的.table-hover
类来实现可悬停的行
<table class="table table-hover">
...
</table>