The Problem

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

Screenshot showing a table from this very blog where each Trek movie title is weirdly wrapped onto 3-4 lines to make the table fit on a narrow phone screen so it reads things like:
Insur
recti
on

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.

Ah, much better

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.

Screenshot showing a table from this very blog where each Trek movie title is not wrapped at all and the table is too narrow so every cell of text overflows into an overlapping Zalgo text message

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.

  1. 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. ↩︎

Comments

3 responses to “Give Up and Use Tables”

  1. @nward you could try looking into the web component called table saw by @zachleat you put the table markup and then wrap that table in the table saw component. Idk if there is a wordpress plugin that assist with this but I’ve had great success with the web component. https://www.zachleat.com/web/table-saw/

    1. @phoopee3 @nward appreciate you Jason! 🙌

      1. Seems like all the cool kids want me to switch to Ghost 😂

What do you think?