Skip to content

Contextual table classes apply tr class instead of td class to individual cells #29290

@kjsalexander

Description

@kjsalexander

Windows 10.0.17763 Build 17763
Chrome Version 76.0.3809.100 (Official Build) (64-bit)
JSBin of the problem: https://output.jsbin.com/zoqonukaru/
Using Bootstrap 4.3.1

When using Contextual Classes (such as table-warning, table-success) on Bootstrap tables, the class on the tr element applies to the entire row as expected, but placing an additional class on one of the td elements does not apply the new color - it continues to have the color from the tr element. I would expect the td element's class and color to take precedence over the parent td element's class and color.

I'm not sure where the fix would go to be properly compiled from a .scss file into the dist .css file, but adding tr > td ~ .table-danger to the dist .css file seems to make the cell-specific coloring work as intended. This fix doesn't apply to single cell rows, but you wouldn't need to color a single cell differently from the row color if your row is a single cell in the first place, so it's hopefully a moot point.

The fix (in compiled css file, so only a little useful):
bootstrap/dist/css/bootstrap.css line 1681

.table-danger,
.table-danger > th,
.table-danger > td {
  background-color: #f5c6cb;
}

to

.table-danger,
.table-danger > th,
.table-danger > td,
tr > td ~ .table-danger {
  background-color: #f5c6cb;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions