I’ve tried to set the width inline with pxs and relative values. I’ve tried to set the CSS width using pxs and relative values. Not only does the table not scale, it doesn’t seem to respond at all to the changes.
I’ve tried different values for the font size, but this also seems to fail to trigger any response.
Tables are always a tricky one to make responsive, but there are a few tricks you can use.
The problem is that any column will only go as narrow as the longest word that is found within it.
So your first column hits the stops when “Doumbek” touches the sides, column 2 is “TREATMENT” in the head, Ect.
If you want to keep the table in it’s current state, you can allow hyphenation in the cells to allow the words to break and wrap. If you do go down that route, I think it’s best to have that in a media query, because otherwise you can end up with a lot of unnecessary word breaks.
Another option is to have a query that minimises the padding and/or letter spacing in the cells.
The other way to go is to have the whole table collapse into a single column, as in this example.
If you mean you want the table to stretch to take all available space then you need to set it to width:100% because tables are shrink to fit otherwise.
table.events{width:100%}
If as Sam suggested above you want to make the table get down to 320px for small mobiles then you would need to use the method shown in my pen above and make it form one column.
I’ve tried values from 1% to 300% and from 1px to 1000000px but the table will not respond. This is what made me think the font size might be key. So far that’s had no effect either. I haven’t tried the padding yet.
take a look at this demo. I just remembered I had sent this same link to one of my developers to implement responsive tables, because she told me tables don’t scale very well.
I still prefer the method in my codepen although it takes a little more effort to set up. It all depends on data as to which is the best method but for variable data widths I think a single columnar approach will work best.
I’m not keen on hiding columns in the table as that just confuses the user and if you can hide the column it begs the question as to whether it was necessary in the first place.
No, that’s what I mean. I’ve been trying to figure out why the table will not respond to different width values but haven’t had any luck. I’ve tried clearing the browser’s history and my reverse proxy’s cache. The changes will not take effect. By this time I’ve tried maybe 30 times to effect changes and the table just seems to have a mind of its own. Right now it seems to have settled on 100% width, even though there’s no width value in the .css file.
Yes, same URL, and this is what I see after clearing the browser’s history. As I said earlier, this table currently has no width attribute either in the markup or the css.
Yes there is a 20% width been added now which wasn’t there before and was not seen in my post #8 inspector where I added a 100% width to show it would work if applied.
If the 20% is changed to 100% then the table will work at full width. It will not however scale smaller than its content and that would need the technique I have mentioned a few times already.
OK, I’m seeing the page respond to the different values now. I need to purge the cache, clear the browsing history and refresh the page. You’r right, it will not scale, so I’ll try to adapt your technique to my needs.
Hope you don’t mind if I pick your brain as I go along.
OK, I’ve managed to make some improvements based on Mr. O’brien’s suggestions.
The first thing I did was to narrow the table by eliminating one column, rewording two or three of the longer entries and reducing the font size just a bit. That in itself helped a lot. The table doesn’t have to switch to a single column 'til 320px.
Now I’m wondering if there’s some way to single out a particular heading in the table. Once the table switches to single column, I want to to make the first heading “Patient” be a different color or perhaps have the original background and be aligned left (along with it’s corresponding entry). The following headings and corresponding entries would be slightly indented. Something like this:
OK, never mind. I couldn’t get this thing to indent, but I hope you get my meaning.