New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table child elements (thead, tbody, tfoot, tr, td, th) should inherit parent background color #29244
Comments
Rereading this after @ysds's summarized things in #28480, a couple comments so far:
|
The inheritance is of BG color is needed when applying a color to the |
The inheritance could present other issues though as shown here: https://codepen.io/emdeoh/pen/OJVxqeG. |
Ah, true, if the background color is translucent. Are any of the v5 background colors for table's translucent? |
We have some translucency coming, but it's more about anticipating what others will try to do with this thing haha. |
Yeah, true 😆 |
Check out #30342 for where my head is at on a bunch of the table changes. Overhauling the docs, changing some features, and putting some of your suggestions to work :D. |
One issue with the linear gradient only on the But if you target the inner cells (td and th), then the shading applies to the cell variants too: It adds a few extra lines of CSS selectors, but it provides a more robust visual appeal (and will stop people from asking why the hover/striping are not applying to cells that have a table variant 😜), which is still a great trade off compared to all the variant rules in v4 One other thing is using the child selector Above row "C" is hovered (which also triggers hover on the parent table |
But other-wise looks great! |
We don't explicitly have examples that show this is possible, and this currently doesn't work in v4. I don't know that this is something we need to explicitly worry about. I hear you on the nesting though, and with nesting hovers. Will keep looking into that. |
The docs (v4) do mention that the table variants can be placed on cells though, and BootstrapVue's user base does take advantage of individual cell variants (it was a popular ask, so we had to add the custom SCSS to handle it for our Vue table components) |
Oh yeah, for sure, just pointing out that it doesn't actually work with those other table modifiers :). I also don't think it's worth the trouble to add additional styles to account for that either, at least for striping—if you want a cell to be a particular color, it should be that color. Actually I guess we could put the |
Yeah, that would work well regardless of where the color is applied (table, tbody, tr, td, or th). If a cell doesn't have a background color, the row's background color will show through, and if the row doesn't have a background color then the background of the row group will show, and so-on and so-on and so-on, and so-on... https://www.youtube.com/watch?v=mcskckuosxQ) |
e.g.: .table-striped {
> tbody > tr:nth-of-type(#{$table-striped-order}) {
> td,
> th {
background-image: linear-gradient($table-accent-bg, $table-accent-bg);
}
}
}
.table-hover {
> tbody > tr:hover {
> td,
> th {
color: $table-hover-color;
background-image: linear-gradient($table-hover-bg, $table-hover-bg);
}
}
} These shading rules wont leak into nested tables |
When working on "sticky header" and "sticky column" features for BootstrapVue (using Bootstrap v4.3.1 CSS), I had to generate a huge amount of SCSS (and conditionals in JS) to ensure that the cells had a background color (they were transparent by default, as table cells do not inherit their parent background color).
It would be nice if Bootstrap set up the table child elements to inherit their parent element's background color, so if a color is applied to a cell, row, or table they will have a solid background.
We also came up with a simple way to generate zebra striping and hover state with much less lines of CSS by cheating with a transparent solid gradient background image (which gets overlayed on the background color).
Something like this would be great in Bootstrap (v5), and it probably would decrease the amount of CSS rules generated (specifically for the them color variants):
If you want to take a peek at what it looks like, check out https://bootstrap-vue.js.org/docs/components/table/#sticky-headers and https://bootstrap-vue.js.org/docs/components/table/#sticky-columns
The only issue we have is that the table borders scroll with the body since tables are set to
border-collapse: collapsed;
(which has the effect of transferring the borders to the table element instead of the cells). Setting that toborder-collapse: separate; border-spacing: 0;
fixes the border scrolling issue, but doubles the borders in some instances... but that could be fixed by only applying border to the left, bottom, and right where needed.Related to #28480, #26678
Here is what a scrollable table with sticky headers looks like without the above changes (cells in behind of the sticky headers show through):
And with the above changes (for background-color inheritance):
/cc @mdo
The text was updated successfully, but these errors were encountered: