{"id":292192,"date":"2019-07-12T15:31:21","date_gmt":"2019-07-12T22:31:21","guid":{"rendered":"http:\/\/css-tricks.com\/?p=292192"},"modified":"2020-03-05T06:24:58","modified_gmt":"2020-03-05T13:24:58","slug":"position-sticky-and-table-headers","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/position-sticky-and-table-headers\/","title":{"rendered":"Position Sticky and Table Headers"},"content":{"rendered":"
You can’t <\/p>\n The issue boils down to the fact that stickiness requires There are two very extreme reactions to this, should you need to implement sticky table headers and not be aware of the The first is dangerous because you aren’t using semantic and accessible elements for the content to be read and navigated. The second is almost the same. You can go that route, but need to be really careful to re-apply semantic<\/a> roles. <\/p>\n Anyway, none of that matters if you just stick (get it?!) to using a \n See the Pen It’s probably a bit weird to have table headers as a row in the middle of a table, but it’s just illustrating the idea. I was imagining colored header bars separating players on different sports teams or something.<\/p>\nposition: sticky;<\/code> a
<thead><\/code>. Nor a
<tr><\/code>. But you can sticky a
<th><\/code>, which means you can<\/em> make sticky headers inside a regular ol’
<table><\/code>. This is tricky stuff, because if you didn’t know this weird quirk, it would be hard to blame you. It makes way more sense to sticky a parent element like the table header rather than each individual element in a row. <\/p>\n
position: relative<\/code> to work and that doesn’t apply to
<thead><\/code> and
<tr><\/code><\/a> in the CSS 2.1 spec. <\/p>\n
<th><\/code> workaround. <\/p>\n
\n
<div><\/code>s and whatnot) and other CSS layout methods to replicate the style of a table, but not locked out of using
position: relative<\/code> and creating
position: sticky<\/code> parent elements.<\/li>\n
display<\/code> values.<\/li>\n<\/ul>\n
sticky<\/code> value on those
<th><\/code> elements. <\/p>\n
\n Sticky Table Headers with CSS<\/a> by Chris Coyier (@chriscoyier<\/a>)
\n on CodePen<\/a>.<\/span>\n<\/p>\ns in the blog post A table with both a sticky header and a sticky first\u00a0column. In it, I never used position: sticky on any , , or
element, because even though Safari and Firefox\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/06\/Screen-Capture-on-2021-06-15-at-06-45-53.gif?fit=1200%2C674&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":333880,"url":"https:\/\/css-tricks.com\/a-table-with-both-a-sticky-header-and-a-sticky-first-column\/","url_meta":{"origin":292192,"position":2},"title":"A table with both a sticky header and a sticky first column","date":"February 9, 2021","format":false,"excerpt":"We've covered that individual cells,
and can be position: sticky. It's pretty easy to make the header of a table stick to the top of the screen while scrolling through a bunch or rows (like this demo). But stickiness isn't just for the top of the screen,\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/02\/table-mlb-teams.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":338846,"url":"https:\/\/css-tricks.com\/sticky-headers-5-ways-to-make-them-better\/","url_meta":{"origin":292192,"position":3},"title":"Sticky Headers: 5 Ways to Make Them Better","date":"April 21, 2021","format":false,"excerpt":"Page Laubheimer says that if you're going to do a sticky header... Keep it small.Visually contrast it with the rest of the page.If it's going to move, keep it minimal. (I'd say, respect prefers-reduced-motion.)Consider \"partially persistent headers.\" (Jemima Abu calls it a Smart Navbar.)Actually, maybe don't even do it. I\u2026","rel":"","context":"In "Link"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/04\/sticky-header.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":282104,"url":"https:\/\/css-tricks.com\/more-like-position-tricky\/","url_meta":{"origin":292192,"position":4},"title":"More Like position: tricky;","date":"February 4, 2019","format":false,"excerpt":"I rather like position: sticky;. It has practical use cases. I think of things like keeping a table of contents in a sidebar of a long article, but as a fairly simple implementation and without risk of overlapping things in awkward ways. But Elad Shechter is right here: it's not\u2026","rel":"","context":"In "Link"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/02\/elad-shechter-sticky-monster-1.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":262902,"url":"https:\/\/css-tricks.com\/idea-simple-responsive-spreadsheet\/","url_meta":{"origin":292192,"position":5},"title":"An Idea for a Simple Responsive Spreadsheet","date":"November 28, 2017","format":false,"excerpt":"How do you make a spreadsheet-like interface responsive without the use of any JavaScript? This is the question I've been asking myself all week as I've been working on a new project and trying to figure out how to make the simplest spreadsheet possible. I wanted to avoid using a\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"featured_media_src_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/07\/table-pattern.png?fit=1024%2C512&ssl=1","_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/292192"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=292192"}],"version-history":[{"count":8,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/292192\/revisions"}],"predecessor-version":[{"id":304726,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/292192\/revisions\/304726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media\/292600"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=292192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=292192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=292192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}