I have an HTML table with 17 columns over 2 header rows and 1 body row. On most desktop views, this table fits nicely with my design, but on small screens the table overhangs its parent element and a significant amount of horizontal scroll is created.
I was wondering if there's a way in CSS/HTML/JS to catch a table going over a certain width, or counting a number of columns (or any other sensible way of doing it), and causing it to 'break' over into a new line, the same way a line break would be added to a paragraph. I want to catch this programatically (rather than just rewriting the table to multiple tables) as the large-screen experience is dramatically better without this hypothetical column-line break.
Ideally I'd like to keep the css definitions of table-cell etc (as in, not just make everything display: block
and be done with it).
To add to the complications, some of the header cells in the top row span two columns. I'm hoping a solution can be found that either doesn't break those cells, or copies the text in the cell to both columns after a break is made.
This is all inside the Foundation 6 framework, if there's any tools there that I've missed. I tried using Foundation's <table class="stack">
, but it doesn't work - it only shows the body row, I think because some of the header cells span multiple columns.