diff --git a/scss/content/_tables.scss b/scss/content/_tables.scss index 781d1f2c797e..b082cd83901a 100644 --- a/scss/content/_tables.scss +++ b/scss/content/_tables.scss @@ -29,6 +29,8 @@ $table-tokens: defaults( --table-hover-color: var(--table-color), --table-hover-bg-factor: 7.5%, --table-hover-bg: color-mix(in srgb, var(--table-color) var(--table-hover-bg-factor), transparent), + --table-thead-sticky-top: 0px, + --table-thead-sticky-zindex: var(--z-3), ), $table-tokens ); @@ -176,6 +178,18 @@ $table-striped-columns-order: even !default; } } + // Sticky table headers + // + // Subtract the collapsed cell border so scrolling rows cannot show through a + // 1px gap at the top of the scrollport. + + .thead-sticky { + position: sticky; + top: calc(var(--table-thead-sticky-top) - var(--table-border-width, 1px)); + z-index: var(--table-thead-sticky-zindex); + background-color: var(--theme-bg-subtle, var(--table-bg)); + } + // Responsive tables // // Generate `.table-responsive` classes that act as container query contexts diff --git a/site/src/content/docs/content/tables.mdx b/site/src/content/docs/content/tables.mdx index 5a65188abdbd..00cd7e8e518e 100644 --- a/site/src/content/docs/content/tables.mdx +++ b/site/src/content/docs/content/tables.mdx @@ -205,7 +205,7 @@ Highlight a table row or cell by adding a `.table-active` class. `} /> -## How do the variants and accented tables work? +## Variants explained For the accented tables ([striped rows](#striped-rows), [striped columns](#striped-columns), [hoverable rows](#hoverable-rows), and [active tables](#active-tables)), we used some techniques to make these effects work for all our [table variants](#variants): @@ -225,7 +225,7 @@ Behind the scenes it looks like this: ## Table borders -### Bordered tables +### Bordered Add `.table-bordered` for borders on all sides of the table and cells. @@ -235,7 +235,7 @@ Add `.table-bordered` for borders on all sides of the table and cells.
| # | +First | +Last | +Handle | +
|---|---|---|---|
| 1 | +Mark | +Otto | +@mdo | +
| 2 | +Jacob | +Thornton | +@fat | +
| 3 | +Larry the Bird | +||
| 4 | +Mark | +Otto | +@mdo | +
| 5 | +Jacob | +Thornton | +@fat | +
| 6 | +Larry the Bird | +||
| 7 | +Mark | +Otto | +@mdo | +
| 8 | +Jacob | +Thornton | +@fat | +
| 9 | +Larry the Bird | +||