MediaWiki talk:Gadget-StickyTableHeaders.css

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

"and firefox's sticky support seems completely broken"[edit]

It's not completely broken, but it doesn't currently work on table cells much like how you point out that Chrome's support doesn't work on <thead>. It looks like the upstream bug for that is 975644. Anomie 14:55, 28 March 2017 (UTC)[reply]

Testing...
...
...
...
...
...
...
...
...
...

Div Header

...
...
...
...
...
...
...
...
...
...

Div Footer

...
...

<th> Header
...
...
...
...
...
...
...
...
...
...
<th> Footer

...
...
...
...
...
...
...
...
...
...

Firefox 59 supports sticky headers[edit]

I know the change was made a while ago in the gadget, but release channel Firefox 59 only popped out this week. Yay! You might consider tweaking the gadget description, which says it requires Safari or Chrome.

However, it looks like Timeless doesn't play well with it? No headers are sticky. :( Vector works. --Izno (talk) 23:01, 17 March 2018 (UTC)[reply]

Still clobbers borders too, but that's a minor offense. --Izno (talk) 23:02, 17 March 2018 (UTC)[reply]
Is it that no headers are sticky, or that they "stick" underneath Timeless's own non-scrolling page header where they're not normally visible? Anomie 14:17, 18 March 2018 (UTC)[reply]
@Anomie: It looked to me (with two rows with of headers, one of which was two lines, ref test page) that they weren't sticky, not that Timeless was clobbering them. I haven't tried with three or four rows of headers. --Izno (talk) 16:22, 18 March 2018 (UTC)[reply]
Headers now sticky in Timeless. Yay. However, references apparently have a higher z-level, so the headers end up displaying with references in front. Firefox 60.0.2. Found this one on ...Baby One More Time (song). --Izno (talk) 14:44, 14 June 2018 (UTC)[reply]
So, the headers are sticky but there's something going on with some weird whitespace displayed only in monitor resolutions. (At sub-monitor resolution, no issue.) The change corresponded with a Thursday deploy I'd guess. --Izno (talk) 18:07, 28 October 2018 (UTC)[reply]
@Anomie and TheDJ: The heights were changed some while ago in Timeless. At least in Firefox, 3.3em fits a lot better for me in the resolutions above 1100px rather than the 6em in the current gadget (the whitespace above is not actually whitespace but the 'background' of the rest of the page). (The 850px-1100px region is still fail.) Would one of you mind adjusting that and/or checking Safari? --Izno (talk) 01:20, 22 November 2018 (UTC)[reply]

Bug: rowspan in headers does not propagate into table[edit]

As found at Help talk:Table#Non-rectangular tables example broken, code such as:

{| class=wikitable
!a
!rowspan=2|b
!c
|-
|x
|z
|}
a b c
x z


does not leave space for column 2 in row 2 (where "b" should spread due to rowspan=2), but instead "z" is immediately adjacent to "x" and the third cell in row 2 is blank. DMacks (talk) 19:30, 28 June 2018 (UTC)[reply]

Well that's not what you are supposed to do with tables. If you stand on your head, things will be upside down. ;) —TheDJ (talkcontribs) 00:46, 29 June 2018 (UTC)[reply]
It's an example from Help:Table. And it gives valid HTML and renders correctly with the gadget off and does not appear to be forbidden or recommended against in the standards. DMacks (talk) 02:37, 29 June 2018 (UTC)[reply]
Tables are also used to layout entire pages. also allowed, renders, just not what they were made for. —TheDJ (talkcontribs) 07:53, 29 June 2018 (UTC)[reply]

@DMacks: So, I've been working to understand TheDJ's argument about why the markup in question is "wrong", and after a lot of investigation, I have to say: I agree.

The issue comes down to how the table renders into HTML, and then how the browser in turn parses that HTML. While the table "looks right" with the sticky-tables gadget turned off, that's only by pure luck, because it's already in an invalid state within the browser's DOM tree. Turning on the gadget merely exposes that invalid state. Using Special:ExpandTemplates, here's the raw HTML for that example table above:

<div class="mw-parser-output"><table class="wikitable">
<tr>
<th>a
</th>
<th rowspan="2">b
</th>
<th>c
</th></tr>
<tr>
<td>x
</td>
<td>z
</td></tr></table>
</div>

But the real problem comes in when Chrome (or any standards-compliant browser) parses that HTML. Because the first row is made entirely of <th> cells, the browser wraps a <thead> around that row. The second row, being that it only contains body cells, goes into <tbody>. Which means that the <thead> and <tbody> are not discrete, because the middle cell occupies both. That's invalid. And since the gadget manipulates the <thead> block of the table, when it's enabled the rendering of that invalid structure breaks.

In the HTML, the table can be corrected by converting the <th rowspan=2> into <td rowspan=2>. When that's done, there are no longer any pure header rows in the table, so the table is parsed as having an empty <thead> and the entire structure in the <tbody>. That's perfectly valid, and displays correctly even with the gadget enabled:

<div class="mw-parser-output"><table class="wikitable">
<tr>
<th>a
</th>
<td rowspan="2">b
</td>
<th>c
</th></tr>
<tr>
<td>x
</td>
<td>z
</td></tr></table>
</div>
a b c
x z

Wikitable syntax doesn't allow mixing regular data cells into column header rows — when a row starts with ! Header !!, all of the cells are header cells even if they have || separators. But, it does allow data rows with header cells mixed into them, via scope="row". Which means that a version of our original nonrectangular table example from Help:Table which is fully compatible with the gadget would look like this:

{| class="wikitable" style="border: none; background: none;"

! scope="row" | Year
! scope="row" | Size 
| rowspan="5" style="border: none; background: none;"|
! scope="row" | Year
! scope="row" | Size 
| rowspan="5" style="border: none; background: none;"|
! scope="row" | Year
! scope="row" | Size 
|-
| 1990 || 1000<br />(est) || 2000 || 1357 || 2010 || 1776
|-
| 1991 || 1010 || 2001 || 1471 || 2011 || 1888
|-
| colspan="2" style="text-align: center;"|⋮
| colspan="2" style="text-align: center;"|⋮
| colspan="2" style="text-align: center;"|⋮
|-
| 1999 || 1234 || 2009 || 1616 || 2019 || 1997<br />(est)
|}
Year Size Year Size Year Size
1990 1000
(est)
2000 1357 2010 1776
1991 1010 2001 1471 2011 1888
1999 1234 2009 1616 2019 1997
(est)

Here again, the table is parsed by the browser as having an empty <thead>. The entire structure is enclosed in the <tbody>, which means it's ignored by the sticky-headers gadget. -- FeRD_NYC (talk) 12:33, 5 July 2018 (UTC)[reply]

In fact, I just tested and the same thing works, and renders correctly, if scope="col" is used on the header cells instead of scope="row". Which is arguably more correct semantically, since the header cells are meant to apply to their column. -- FeRD_NYC (talk) 12:54, 5 July 2018 (UTC)[reply]

Borders in sticky headers[edit]

Border=1 is in HTML5. Rules=all and cellpadding=x are not. Just wondering if any of this might help.


{| class=wikitable

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3


{|

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3


{| border=1

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3


{| rules=all

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3


{| border=1 rules=all

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3


{| border=1 rules=all cellpadding=3

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3



It looks like rules=all might somehow solve the header borders problem. -- Timeshifter (talk) 22:36, 31 May 2019 (UTC)[reply]

border-collapse works and is HTML5 compliant[edit]

I forgot to mention I am using Firefox.

border=1 is also HTML5 compliant, and must also be used for this to work.

{| border=1 style=border-collapse:collapse;

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3

By the way, for those who don't know, the table is from the "insert a table" button on the 2006 editing toolbar. A similar table can be had from clicking the table button in the advanced menu of the 2010 editing toolbar.

See: Special:Preferences#mw-prefsection-editing. There one can enable this:

  • Enable the editing toolbar. This is sometimes called the '2010 wikitext editor'.

I normally have the 2006 editing toolbar (plus extensions) enabled. I have the following 3 gadgets enabled in the editing section of gadget preferences:

  • Enable the legacy (2006) editing toolbar. This will be overridden by the "Enable the editing toolbar" option in the Editing tab.
  • refToolbar: add a "cite" button to the editing toolbar for quick addition of commonly used citation templates
  • Add extra buttons to the old (non-enhanced) editing toolbar

They just add more buttons to the 2006 editing toolbar. Unfortunately, both toolbars can not be enabled at the same time. The 2010 preference will override the 2006 preference setting. --Timeshifter (talk) 09:26, 1 July 2019 (UTC)[reply]

Row headers in sticky[edit]

You might want to take a look at what turning stick on does to the row headers in this table in Firefox. As you scroll up the page, the row headers in the bottom half of the table start to overlap and obscure those in the top of the table. SpinningSpark 18:27, 2 May 2020 (UTC)[reply]

Character 1 2 3 4 5 6
А П
Б Л
В
Г
Д
Е
Ж
З
И
К
Л
М
Н
О
П
Р
С
Т
У
Ф
Х
Ц
Ч
Ш
Щ
Ъ
Ы
Ь
Э
Ю
Я

This is expected. The table is not complete. The script that enhances the functionality tries to build thead/tfoot's by looking at if a row consists solely of th cells, which these last rows do. It does't do an entire cell count on the table to figure out if the table is wellformed (tablesorter DOES do this, but it's way more advanced in how it analyzes tables). —TheDJ (talkcontribs) 14:02, 1 September 2021 (UTC)[reply]

Sticky headers not working with scrollable tables (Timeless)[edit]

So, it doesn't work with Timeless anymore. While I'm really not sure how to fix this, from a brief investigation, it looks like the issue is with the css - position:sticky appears to not play well with overflow:hidden/scroll or some such, for whatever reason?

Dunno, but I'm about to have entirely too much fun attempting to implement sticky scrollbars, and as a result of this rather stupid limitation that might just need to go full CodeMirror... mind you, if this actually does turn out to work, that might actually be the way to go here for better cross-skin and -browser support anyway. Maybe. -— Isarra 21:04, 14 December 2020 (UTC)[reply]

See also: Help talk:Table#Sticky table headers?. It has some recent comments, links, and examples. --Timeshifter (talk) 00:41, 16 December 2020 (UTC)[reply]

Request update[edit]

Request to update the CSS of this gadget to the below source. This should enable the code on Chrome, but more importantly should deal with the issue of missing borders in the sticky content. It also

/* Safari 14 has an issue where table captions interfere with a proper offset */
/* Works with Chrome 91 and later */
/* Works with Firefox v59 and later */
/* Timeless has a problem on Chrome and Safari to apply the extra offset  to clear its sticky header */
/* The CSS can also be used without the gadget's JS, but in that case can only deal with header cells in the first row */

/*
 * Applies to to tablesorter and sticky header gadget created theads/tfoots.
 * These theads can be multi row.
 * If either of these were not applied, apply to the th cells of the first row.
 */
.jquery-tablesorter > thead,
.mw-sticky-header > thead,
.wikitable:not(.jquery-tablesorter):not(.mw-sticky-header) > tbody > tr:first-child > th {
    position: sticky;
    top: 0;
    z-index: 12;
}

.jquery-tablesorter > tfoot,
.mw-sticky-header > tfoot {
	position: sticky;
    bottom: 0;
    z-index: 12;
}

/*
 * Change the borders of wikitables to work without border collapse
 * Border collapse cannot be applied to sticky elements (technical restriction)
 */
.wikitable {
    border-collapse: separate;
    border-spacing: 0;
    border-bottom-style: none;
    border-left-style:none;
}

.wikitable > * > tr > th, .wikitable > * > tr > td {
    border-right-style: none;
    border-top-style:none
}

/* This additional offset seems broken in Safari and Chrome */
/* This does not always seem to work, possibly due to the absolute/relative hacking mess of timeless */
@media screen and (max-width: 1099px) and (min-width: 851px) {
	.skin-timeless .jquery-tablesorter > thead,
	.skin-timeless .mw-sticky-header > thead,
	.skin-timeless .wikitable:not(.jquery-tablesorter):not(.mw-sticky-header) > tbody > tr:first-child > th {
		top: 3.125em;
	}
}

@media screen and (min-width: 1100px) {
	.skin-timeless .jquery-tablesorter > thead,
	.skin-timeless .mw-sticky-header > thead,
	.skin-timeless .wikitable:not(.jquery-tablesorter):not(.mw-sticky-header) > tbody > tr:first-child > th {
		top: 6em;
	}
}

Also please update MediaWiki:Gadget-StickyTableHeaders to read: Make sure that headers of tables remain in view as long as the table is in view (requires Chrome 91+, Firefox v59+ or Safari) Thank you, —TheDJ (talkcontribs) 13:58, 1 September 2021 (UTC)[reply]

Ping me if I don't get to this in the next day or two. IznoPublic (talk) 02:15, 10 September 2021 (UTC)[reply]
 Done Izno (talk) 03:29, 10 September 2021 (UTC)[reply]

Interface-protected edit request on 23 July 2022[edit]

Please add the following before line 24, to let the sticky table headers take into account the sticky vector header

@media screen and (min-width: 1000px) {
	.skin-vector-2022.vector-sticky-header-visible .jquery-tablesorter > thead,
	.skin-vector-2022.vector-sticky-header-visible .mw-sticky-header > thead {
		top: 3.125rem;
	}
}

TheDJ (talkcontribs) 11:48, 23 July 2022 (UTC)[reply]

 Donexaosflux Talk 12:01, 23 July 2022 (UTC)[reply]

Error on table wrapped in style="overflow:auto"[edit]

An issue with 2022–23 NCAA Division I women's basketball rankings#AP Poll was reported at Wikipedia:Village pump (technical)#Truncated tables. In Vector 2022 the contents of the header row moves down on top of the next row when the gadget runs. Also, the header is not sticky but remains on top of the next row. The table is made with {{ColPollTable}}. Special:ExpandTemplates shows that the produced table code is wrapped in <div style="overflow:auto">...</div>. If this code is removed then the table appears to display correctly. PrimeHunter (talk) 01:46, 4 February 2023 (UTC)[reply]

Yes this is a known problem with sticky. Sticky is always relative to the first scrollcontext. So if you wrap something in an overflow:auto, your headers become relative to that, instead of the rest of the page, yet its offset is still the sticky skin header. This is one of the reasons why adding sticky headers is so problematic. —TheDJ (talkcontribs) 10:22, 4 February 2023 (UTC)[reply]
i'm wondering if CSS4 container queries could help solve that.. Something worth experimenting with. —TheDJ (talkcontribs) 10:48, 4 February 2023 (UTC)[reply]
In Vector Legacy it isn't sticky either but it's displayed in the right place at top of the table and not on top of the next row. It would be nice to at least get that in Vector 2022. PrimeHunter (talk) 15:14, 4 February 2023 (UTC)[reply]
Legacy vector doesn’t have a sticky toolbar to take into account on the offset —TheDJ (talkcontribs) 22:51, 4 February 2023 (UTC)[reply]

Proposal to add toggle[edit]

The gadget is great on many long tables but some tables display incorrectly or poorly so I haven't enabled it. Also, as an editor I often want to see what normal readers see. I have made a script User:PrimeHunter/Sticky headers.js which adds a link under "Tools" to reload the current page with the gadget code, for users who haven't enabled the gadget. I propose the gadget itself adds a disable/enable toggle, maybe only for the current page, or maybe remembering the setting until the next click. PrimeHunter (talk) 01:02, 15 February 2023 (UTC)[reply]

Agreed; that would be a nice enhancement. Mathglot (talk) 18:34, 19 March 2023 (UTC)[reply]

Sticky headers on smartphone browsers[edit]

Hey, I tried the sticky headers on the smartphone browsers of Firefox and Free Adblock browsers. Both browsers don't show the sticky headers in the mobile view of Wikipedia.

While the browser on my desktop PC shows the sticky headers in both the desktop and mobile view of WP.

https://en.wikipedia.org/wiki/List_of_Airbus_A320_family_operators

Can you make the sticky browsers work on smartphone browsers? :) WikiPate (talk) 15:38, 15 October 2023 (UTC)[reply]

Set z-index to the sticky header[edit]

If there are absolutely-positioned elements like at Corruption Perceptions Index#Rankings, the header ends up like this:

This seems to be easily fixed by setting z-index: 1; to the header (not sure about the value). Jack who built the house (talk) 10:09, 28 April 2024 (UTC)[reply]

And also it distorts the table header:

Jack who built the house (talk) 17:45, 4 May 2024 (UTC)[reply]