Performance: Striped and hover tables
This affects the rendering speed and visual stability of tables by adding background color styles for rows.
<table class="table table-striped table-hover"> <tbody> <tr><td>Row 1</td></tr> <tr><td>Row 2</td></tr> <tr><td>Row 3</td></tr> </tbody> </table>
<table> <tr style="background-color:#f8f9fa"><td>Row 1</td></tr> <tr><td>Row 2</td></tr> <tr style="background-color:#f8f9fa"><td>Row 3</td></tr> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline styles with JS hover | Minimal DOM ops | Multiple reflows on hover | High paint cost on hover | [X] Bad |
| Bootstrap .table-striped and .table-hover | Minimal DOM ops | No reflows on hover | Low paint cost on hover | [OK] Good |
table-striped class do in a Bootstrap table?table-stripedtable-striped class adds alternating background colors to rows, making it easier to read data across the table.table-hover class highlights rows on mouse hover, which is different from table-striped.table class plus additional classes separated by spaces, like table-striped and table-hover.<table class='table table-striped table-hover'> correctly uses class='table table-striped table-hover'. Order doesn't matter but all classes must be present and spelled correctly.table plus both classes [OK]<table class='table table-striped table-hover'> <tr><td>Row 1</td></tr> <tr><td>Row 2</td></tr> <tr><td>Row 3</td></tr> </table>
table-striped and table-hover classes together.table-striped adds alternating row colors, and table-hover highlights the row under the mouse pointer.<table class='table table-striped hover'> <tr><td>Data</td></tr> </table>
hover alone is not a valid Bootstrap class for hover effect.table-hover, which must be used with the base table class.table-hover, not just hover. -> Option Ctable-hover class [OK]table-striped and table-hover with the base table class for row effects.table-dark on the <thead> element to style the header with a dark background.table-dark on the whole table changes entire table style, not just header. thead-dark is deprecated in Bootstrap 5+. table-header-dark is not a valid class.table-dark on thead for dark header [OK]Pass the test and this pattern moves unknown