News for hackers. Stuff that matters.
Re:Responsive Tables in Pure CSS by JoshTriplett on Monday April 06, 2015 @12:43PM (#9329056)
This seems like an impressive approach for data that uses a table for grouping but remains understandable when grouped linearly with duplicated labels.

However, for tables showing genuinely tabular data, I'd almost always prefer to just see the original table and scroll horizontally, perhaps with appropriate heading columns or rows fixed so that they always display.

Does anyone have appropriate CSS that produces an effect similar to "position: fixed" but only for horizontal scrolling, not for vertical scrolling? Or only for vertical scrolling, with it scrolling off the screen when scrolling away the last row of the table?

Imagine the following as a large table:

         | col1 | col2 | col3
    row1 |  d11 |  d12 |  d13
    row2 |  d21 |  d22 |  d23
    row3 |  d31 |  d32 |  d33
Scrolling horizontally should keep the row labels visible, and scrolling vertically should leave the column labels visible until the last data row is scrolled off the screen. And ideally that should not require any JavaScript.
Re:Responsive Tables in Pure CSS by kolme on Monday April 06, 2015 @01:23PM (#9329322)
Yes, it can be easily done with a combination of divs, fixed width and overflow-x: scroll.

But I doubt one can do that with a table only, which is a shame, because it would lose markup semantic.

Edit: Little PoC http://codepen.io/anon/pen/LEoyrK

Re:Responsive Tables in Pure CSS by 91bananas on Monday April 06, 2015 @04:38PM (#9330562)
Nearly every solution for this I have seen or implemented uses a combination of 2 divs with tables inside to work the scrolling. Tables just aren't built to do that well in my opinion.
Re:Responsive Tables in Pure CSS by Silhouette on Tuesday April 07, 2015 @12:43AM (#9332053)
Nearly every solution for this I have seen or implemented uses a combination of 2 divs with tables inside to work the scrolling.

Yes, we use a variation of that theme as well.

It works to a useful degree, as long as you have enough control over the dimensions that you don't wind up with the row heights differing between the row headers table and the data rows table.

Of course the mark-up is semantically poor, but then HTML's enforced columns-inside-rows nesting for tables is already horrible to work with if you want to show a data record per column and use the row labels for the fields rather than vice versa, making any sort of templating system fragile as well. Rather like floats, this is one of those areas where no amount of CSS tweaks can now make up for underlying weaknesses in the spec of HTML itself.

Tables just aren't built to do that well in my opinion.

We could do better than what we have, though. Hopefully we will before too long, if position:sticky becomes standardised, complete with the notes about making it work properly in a tabular context where some other positioning explicitly isn't required to.

I'm not sure how effectively we'll be able to write a comprehensive polyfill without resorting to JS, so maybe we'll have to settle for gracefully degrading to having the entire table scroll without locking the row headers in place. At least the table mark-up will be more sensible than having two completely separate table elements with some sort of wrapper(s).

Re:Responsive Tables in Pure CSS by psychometry on Monday April 06, 2015 @01:10PM (#9329210)
You can apply `position: fixed` to a `thead` element, but you need to either exactly specify or calculate (and recalculate on resize) all of the column widths in pxs.
Re:Responsive Tables in Pure CSS by mxtopher on Monday April 06, 2015 @12:48PM (#9329092)
Hi there, take a look on position: sticky; It does exactly what you want. Please note it is still experimental though.