June 15, 201412 yr When you need to have tabular data, how do you make your tables responsive? I usually either build a fake table made out of divs (when possible) or if it's a complex table, I show it as table down to the point when it doesn't fit the screen anymore, then hide it and show the table content in a div. I would be interested to see if there is a better way / what's your preferred solution.
June 15, 201412 yr I go for the route of wrapping the table in a container e.g. <div class="tableContainer"> <table> </table> </div> . I then display the table as normal until it no longer fits. Then apply the CSS via media query: .tableContainer { overflow-x:scroll; -webkit-overflow-scrolling:touch; width:100%; } This allows you to scroll the table left/right including on iPhone/iPad etc. Usually works for me.
June 15, 201412 yr Mikes answer is a good one, that's what I do. You shouldn't use divs, as a table is designed to hold tabular data and as we all know we should use the appropoate tags. The way I lay my tables out are as follows: Firstly it's good to use some kind of grid system that is consistent. 24 columns is a nice easy number to work with, we need to ensure that one column is always the same width across all the tables. We can do this via a very useful property that you can add to your tables: table { table-layout: fixed; } Now to make sure each row has 24 columns we can use the colspan attribute on each cell. on every row the number of colspans must equal 24. Using this we can have a tonne of flexibility regarding the layout of our tables that always remains consistent. I created a fiddle to demonstrate this: http://jsfiddle.net/dy8ej/ If for some reason you want to lay things out using divs, still use the table tags but set their display properties to block then they will behave in the same manner as any block element i.e. a div. . Edited June 15, 201412 yr by rbrtsmith
June 16, 201412 yr I used a different approach using a real table and then off screen the th row when to small and using a css before for the col names. @media only screen and (max-width : 480px) { .table-list table, .table-list thead, .table-list tbody, .table-list th, .table-list td, .table-list tr { display: block; } .table-list thead tr { position: absolute; top: -9999px; left: -9999px; } .table-list td:nth-of-type(2):before { content: "Col One Name: "; } .table-list td:nth-of-type(3):before { content: "Col Two Name: "; } .table-list td:nth-of-type(4):before { content: "Col Three Name: "; } .table-list td:nth-of-type(5):before { content: "Col Four Name: "; } } Which creates a separated list look for smaller screens.
June 16, 201412 yr here are some techniques mentioned Lol my method is 'No More Tables' on your list Edited June 16, 201412 yr by BrowserBugs
June 19, 201412 yr Add this media query into your css style sheet. @media only screen and (max-width : 320px) { .table { display: block; height: 300px; margin: 0; overflow: scroll; } } After adding this code to in your style sheet yhe table will be working as good.
Create an account or sign in to comment