Template:Sticky table start/styles.css

From RetroWikipedia
Revision as of 02:52, 3 August 2025 by imported>Jroberson108 (Adjust "Sticky Table Headers" gadget fix.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
/* {{pp-template}} */
/**
 * Classes to make row N or thead top sticky, and/or column N left sticky.
 *
 * Div classes:
 * - sticky-table-scroll: Adds scroll; contains table.
 *
 * Table classes:
 * - sticky-table-head: Top sticky thead rows.
 * - sticky-table-row1: Top sticky first row.
 * - sticky-table-row2: Top sticky second row.
 * - sticky-table-col1: Left sticky first column.
 * - sticky-table-col2: Left sticky second column.
 *
 * Cell classes:
 * - sticky-table-none: Cell not sticky to fix span issues.
 * - sticky-table-left: Cell left sticky to fix span issues.
 *
 * Notes:
 * - Sortable moves to thead any header rows and (after sort) sorttop rows.
 * - Sticky gadget (.mw-sticky-header) moves to thead any wikitable header rows.
 */
@media screen {
  /**
   * Div containers with restricted height/width + scroll.
   */
  .sticky-table-scroll {
    margin-bottom: 1em; /* Moved from table. */
    margin-top: 1em; /* Moved from table. */
    max-height: 75vh;
    max-width: max-content; /* Vertical scroll next to div. */
    min-width: 50px; /* In case another element floats right. */
    overflow-y: auto;
    /*scrollbar-gutter: stable; /* Fix premature wrapping Gecko: 764076. */
  }
  .sticky-table-scroll table {
    margin-bottom: 0; /* Moved to div. */
    margin-top: 0; /* Moved to div. */
  }
  .sticky-table-scroll caption {
    text-align: left; /* Fix narrow, centered caption hidden on wide table. */
  }

  /**
   * Make top sticky.
   */
  .sticky-table-scroll .sticky-table-row1:not(.sticky-table-row2):not(.sticky-table-head) > thead > tr:nth-child(1),
  .sticky-table-scroll .sticky-table-row1:not(.sticky-table-row2):not(.sticky-table-head) > caption + tbody > tr:nth-child(1),
  .sticky-table-scroll .sticky-table-row1:not(.sticky-table-row2):not(.sticky-table-head) > tbody:first-child > tr:nth-child(1),
  .sticky-table-scroll .sticky-table-row2:not(.sticky-table-row1):not(.sticky-table-head) > thead > tr:nth-child(2),
  .sticky-table-scroll .sticky-table-row2:not(.sticky-table-row1):not(.sticky-table-head) > caption + tbody > tr:nth-child(2),
  .sticky-table-scroll .sticky-table-row2:not(.sticky-table-row1):not(.sticky-table-head) > tbody:first-child > tr:nth-child(2),
  .sticky-table-scroll .sticky-table-head:not(.sticky-table-row1):not(.sticky-table-row2) > thead {
    position: sticky; /* Was "static". */
    top: 0;
    z-index: 10;
  }

  /**
   * Make left sticky.
   */
  .sticky-table-scroll .sticky-table-col1:not(.sticky-table-col2) > * > tr > :nth-child(1):not(.sticky-table-none),
  .sticky-table-scroll .sticky-table-col2:not(.sticky-table-col1) > * > tr > :nth-child(2):not(.sticky-table-none),
  .sticky-table-scroll tr > .sticky-table-left {
    position: sticky; /* Was "static". */
    left: 0;
    z-index: 9;
  }

  /**
   * Fix scrolling data shows through sticky's transparent background.
   */
  .sticky-table-scroll table:not(.wikitable) {
    background-color: var(--color-inverted, #fff);
  }
  .sticky-table-scroll thead,
  .sticky-table-scroll tbody,
  .sticky-table-scroll tfoot,
  .sticky-table-scroll tr,
  .sticky-table-scroll td,
  .sticky-table-scroll table:not(.wikitable) > * > tr > th {
    background-color: inherit;
  }

  /**
   * Fix missing borders due to sticky position and wikitable collapsed borders.
   * https://bugs.webkit.org/show_bug.cgi?id=128486
   *
   * Skip rare plain table separated borders, which sometimes shows scrolling
   * data through sticky's 2px "border-spacing".
   *
   * Skip very rare Timeless plain table ".mw-datatable" collapsed borders.
   *
   * Note: {{Static row numbers}} border separating header/sorttop from numbers
   * missing and may not be fixable until RetroWikipedia supports newer CSS.
   */
  .sticky-table-scroll .wikitable {
    border-collapse: separate; /* Was "collapse". */
    border-spacing: 0;
    border-width: 1px 0 0 1px;
  }
  .sticky-table-scroll .wikitable > * > tr > td,
  .sticky-table-scroll .wikitable > * > tr > th {
    border-width: 0 1px 1px 0;
  }
  /* Adjust {{static row numbers}} borders. */
  .sticky-table-scroll .static-row-numbers.wikitable > * > tr::before {
    border-right-width: 1px;
  }
  /* .sticky-table-scroll .static-row-numbers.wikitable > * > .sorttop:not(:has(~ .sorttop))::before, */
  .sticky-table-scroll .static-row-numbers.wikitable > tbody > tr:last-child::before,
  .sticky-table-scroll .static-row-numbers.wikitable > tfoot > tr:last-child::before {
    border-bottom-width: 1px;
  }
  .sticky-table-scroll table.static-row-numbers.wikitable > tbody > tr:not(.static-row-header)::before {
    border-top-width: 0;
    border-left-width: 0;
  }

  /**
   * Fix Timeless skin very wide tables not sticky.
   */
  body.skin-timeless .sticky-table-scroll .overflowed,
  body.skin-timeless .sticky-table-scroll .overflowed .content-table {
    overflow: visible; /* Reset. */
  }
  body.skin-timeless .sticky-table-scroll .overflowed {
    margin-top: 0; /* Was "1em". */
    margin-bottom: 0; /* Was "1em". */
  }
  body.skin-timeless .sticky-table-scroll .scroll-right.overflowed .content-table-right {
    box-shadow: none; /* Reset. */
    border-left: none; /* Reset. */
  }
  body.skin-timeless .sticky-table-scroll .wikitable {
    padding: 0;
  }

  /**
   * Fix VisualEditor (VE) removing scrollable and hiding content.
   */
  html.ve-activated .sticky-table-scroll {
    max-height: none; /* Unhide. */
  }
}

/**
 * Fix skins width <=639px (mobile) not sticky.
 */
@media screen and (max-width: 639px) {
  body.skin-minerva .sticky-table-scroll table,
  body.skin-monobook .sticky-table-scroll table,
  body.skin-vector-legacy .sticky-table-scroll table,
  body.skin-vector-2022 .sticky-table-scroll table {
    display: table; /* Was "block". */
  }
  body.skin-minerva .sticky-table-scroll caption {
    display: table-caption; /* Was "block". */
  }
}

/**
 * Fix "Sticky Table Headers" gadget styles causing sticky issues.
 */
@media screen and (min-width: 1120px) {
  /* For sortable wikitable/plain without top-sticky thead. */
  body.skin-vector-2022.vector-sticky-header-visible .sticky-table-scroll .jquery-tablesorter > thead {
    top: 0; /* Was "3.125rem". */
  }
  /* For non-sortable wikitable without top-sticky thead. */
  html.vector-sticky-header-enabled body.skin-vector-2022 .sticky-table-scroll .mw-sticky-header-element {
    top: 0 !important; /* Was "3.125rem". */
  }
}