The Problem
As Joe noted, when I first published my Trek movie list, the tables got super weirdly wrapped on mobile.

I don’t often format data in posts with tables1, but I had seen this before in previous posts and just not gotten around to fixing it. I still need to muck around more with my headers and margins, too.
The Fix
I found a responsive tables guide for WordPress, but had to tweak it a bit. First, I added the CSS to my theme by going to Appearance > Editor, selecting Styles, selecting the Edit button, and navigating to Additional CSS in the right hand nav panel. In that field I added:
@media only screen and (max-width:768px) {
.wp-block-table {
overflow-x: scroll;
display: block;
white-space: nowrap;
}
}
This uses the existing class for the table block and overrides the properties when the screen is phone-sized so that the table scrolls left-to-right.
One thing I can’t figure out is how to style it to indicate that the content is scrollable, since in the glorious flat design mobile OS future scrollbars don’t appear until interacted with. It seems this isn’t built in without excess JavaScript layers?
While this CSS override applies to my entire theme, there is still one additional step to get each table to behave right: in each table’s Block settings you need to toggle off “Fixed width table cells”, which removes the .has-fixed-layout class from the table, which would apply table-layout: fixed; to it. If you don’t do this, and the first row’s cell in a column is narrow, the nowrap setting above would cause the text to overflow the cells.

But why?
A broader problem with using WordPress and a default theme like twentytwentyfour is that I don’t and probably can’t understand the complexity because I didn’t built the layout myself. All I can do is try to find some override hooks that get the result I want. Anything more, where I try to own more of the layout, can easily lead me down the dangerous path of rolling my own CMS.
I don’t fully understand why this kind of table layout doesn’t just work out of the box on mobile; I suspect the short answer is that almost no one needs semantic tables in their blogs or sites and so the feature gets very little attention. I know there are a lot of table plugins or other options out there but I personally want to use the out-of-the-box WordPress setup as much as possible so that I can minimize my support effort and avoid any long term migrations.
- The title of this post is a reference to an old single serving site about using tables for web layout in an earlier design era. ↩︎
What do you think?