UX4G's tables are opt-in due to the widespread use of
<table> components across third-party widgets like calendars and date
pickers. Any <table> can be extended with optional modifier classes
or unique styles after adding the base class.table. Since none of the table styles in
UX4G are inherited, any nested tables can have their own styling independent of the
parent table.
Here's how, using the most fundamental table markup.UX4G's table-based
tables appear.
Color-coding to add meaning just gives a visual cue, which users of assistive
technologies like screen readers won't be able to understand. Make sure the information
the colour designates is either evident from the content itself (such as the visible
text) or is included in another way, such as by hiding additional text using the
.visually-hidden class.
Using color to add meaning only provides a visual indication, which will
not be conveyed to users of assistive technologies – such as screen
readers. Ensure that information denoted by the color is either obvious
from the content itself (e.g. the visible text), or is included through
alternative means, such as additional text hidden with the
.visually-hidden class.
There are several methods to ensure that these effects appeared on all of the table
variations for the accented tables (striped rows, striped columns,
hoverable rows, and active tables):
Starting off, use the custom property --bs-table-bg to change a table
cell's background colour. The custom attribute is then set in all table variations
to colourize the table cells. In this approach, if semi-transparent colours are
chosen for table backdrops, avoid any issues.
Then, to layer on top of any supplied background-color, place an inset box shadow on
the table cells with the following syntax: box-shadow: inset
0 0 0 9999px var (--bs-table-accent-bg); The colour will be monotone
because there is a utilisation of wide spread and didn't apply any blur. It doesn't
have a default box-shadow because --bs-table-accent-bg is unset by
default.
The --bs-table-accent-bg property is used to colourize the background when the
.table-striped, .table-striped-columns,
.table-hover, or .table-active classes are added.
We create a --bs-table-accent-bg colour for each table version based on the colour
that has the highest contrast. For instance, .table-primary has a
darker accent colour than .table-dark, which has a lighter accent
colour.
The same algorithm is used to produce both text and border colours, and
by default, those colours are inherited.
Add a thicker border, darker between table groups—, , and
—with .table-group-divider. Customize
the color by changing the border-top-color
(which we don't currently provide a utility class for at this time).
Table cells are always positioned at the bottom and vertically aligned. Table cells in
and by default have top alignment, which they inherit from. To realign when necessary,
use the
vertical align
classes.
Heading 1
Heading 2
Heading 3
Heading 4
This cell inherits vertical-align: middle;
from the table
This cell inherits vertical-align: middle;
from the table
This cell inherits vertical-align: middle;
from the table
This here is some placeholder text, intended to take up
quite a bit of vertical space, to demonstrate how the
vertical alignment works in the preceding cells.
This cell inherits vertical-align: bottom;
from the table row
This cell inherits vertical-align: bottom;
from the table row
This cell inherits vertical-align: bottom;
from the table row
This here is some placeholder text, intended to take up
quite a bit of vertical space, to demonstrate how the
vertical alignment works in the preceding cells.
This cell inherits vertical-align: middle;
from the table
This cell inherits vertical-align: middle;
from the table
This cell is aligned to the top.
This here is some placeholder text, intended to take up
quite a bit of vertical space, to demonstrate how the
vertical alignment works in the preceding cells.
<divclass="table-responsive"> <tableclass="table align-middle"> <thead> <tr> ... </tr> </thead> <tbody> <tr> ... </tr> <trclass="align-bottom"> ... </tr> <tr> <td>...</td> <td>...</td> <tdclass="align-top">This cell is aligned to the top.</td> <td>...</td> </tr> </tbody> </table> </div>
We employ the child combinator (>) selector in our CSS to stop styles from
leaking to nested tables. In order to target every td and th in the thead, tbody, and
tfoot, we need this selector, which would otherwise appear quite long. As a result, we
employ the peculiar-looking.All tds and ths of the.table are targeted by the
table >:not(caption) > * > * selector, but none of the possible nested
tables are.
Remember that our selectors will function as planned if you add tr>s as direct children
of a table since those <tr> will automatically be wrapped in a
<tbody>.
A functions like a heading for a
table. It helps users with screen readers to find a table and understand
what it's about and decide if they want to read it.
Tables that are responsive can easily be scrolled horizontally. Wrapping a
.table in .table-responsive will make any table responsive
across all viewports. Alternately, you may specify a maximum breakpoint by using the
.table-responsive {-sm|-md|-lg|-xl|-xxl} keyword.
Overflow-y: hidden, which clips off material that extends past the
bottom or top margins of the table, is a technique used in responsive tables. This
can specifically clip off third-party widgets like dropdown menus.
To generate responsive tables up to a specific breakpoint, use
.table-responsive{-sm|-md|-lg|-xl|-xxl}. The table will act appropriately
after that breakpoint and won't scroll horizontally.
The factor variables ($table-striped-bg-factor,
$table-active-bg-factor & $table-hover-bg-factor) are used
to determine the contrast in table variants.
Apart from the light & dark table variants, theme colors are lightened by the
$table-bg-scale variable.