The article doesn't explain all tricks they use. A media query is used to apply the stylesheet selectively to small window sizes. That stylesheet splits the table into multiple ones. The original table's border is removed, and every tr is styled to look like a table by giving it a border. tds are turned into rows by setting display:block. The td rows are given row headers using pseudo elements, which pulls their cont…
Responsive Tables in Pure CSS
21–30 of 74 posts
Re: Responsive Tables in Pure CSS
#22However, 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
#23Re: Responsive Tables in Pure CSS
#24A media query? Dang Living Social tearing up the engineering scene over here.
He is using attr(data-label); to pull the titles from the data attributes and then uses Pseudo Elements to add the title to each td while displaying them in blocks. The end effect is very nice and requires no JS.
Re: Responsive Tables in Pure CSS
#25This 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 e…
Re: Responsive Tables in Pure CSS
#26Interesting read, but why no JS? Don't all mobile devices play well with JS? Is it a file size issue?
Why add JS if it isn't necessary?
1) Maintainability. JS is probably easier to grok in some circumstances, ie. you don't have to send new devs to a blog post to explain the CSS on your project.
2) Cost/benefit analysis of dev time, ie. you could do X (where X is some minor display that 1% of your users see) in pure CSS in 12 hours, or do the same in 30 min of JS.
3) Cost/benefit analysis of page size, ie. you can do in 4 lines of JS what would take 400 lines of CSS. Sometimes a few lines of jQuery obviates several hundred lines of CSS (between the media queries, browser-specific overrides, and so forth).
The interesting question the article should address was why the CSS solution was a better choice than the JS solution. I have a gut feeling the answer is way better than "we just wanted CSS only for purity's sake", and personally I'm interested in knowing what that answer is!
Re: Responsive Tables in Pure CSS
#27Small version: http://i.imgur.com/sJOxCQw.png
Large version: http://i.imgur.com/xrJ4sBt.png
Re: Responsive Tables in Pure CSS
#28Re: Responsive Tables in Pure CSS
#29First a disclaimer: I am a programmer, not a designer or UX specialist. When I make a responsive table I feel like turning every column into a distinct row makes it more difficult to navigate; instead I prefer to split the columns into groups and wrap them with alternate coloring. So if there are 5 columns maybe 3 go in the top of the row and 2 go in the bottom of the row (top and bottom sharing the same background c…
Re: Responsive Tables in Pure CSS
#30This 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 e…