Skip to content

Docs site: stop tables and inline code from overflowing the page on phones - #4235

Open
ngocanhnckh wants to merge 1 commit into
bigskysoftware:masterfrom
ngocanhnckh:fix/docs-table-overflow
Open

ngocanhnckh wants to merge 1 commit into
bigskysoftware:masterfrom
ngocanhnckh:fix/docs-table-overflow

Conversation

@ngocanhnckh

Copy link
Copy Markdown

Description

On htmx.org/docs/ the page scrolls sideways at phone widths, and again between about 740px and 770px:

  • At 320-400px the "Request Headers" table (and other plain markdown tables) is wider than the column, so the page is 85px (320), 45px (360), 30px (375) and 5px (400) wider than the screen. Long inline code (CDN URLs, htmx.config.historyRestoreAsHx) adds to it at 320px.
  • At 740-770px the two-column layout is active but the Config table (.info-table, 539px wide) does not fit the column, so the page is 79px (740) / 69px (760) wider than the window.

Root cause, in www/themes/htmx-theme/static/css/site.css:

  • .info-table only gets overflow-x: scroll inside @media(max-width:45rem), but the .row switches to its two-column layout at min-width:45em and is still too narrow until about 780px.
  • Plain tables (not wrapped in .info-table) are never scrollable.
  • Inline code in paragraphs and list items cannot wrap.

Fix (13 added lines, no existing rule changed):

  • .info-table { overflow-x: auto; } at every width.
  • Inside the existing max-width:45rem block, .content table { display: block; overflow-x: auto; } so plain tables scroll inside the column on phones. Desktop table layout is unchanged.
  • .content p code, .content li code { overflow-wrap: anywhere; } so long inline code wraps.

Same table/code overflow also happened on other pages (/api/, /events/, /attributes/hx-trigger/, /examples/delete-row/, /extensions/response-targets/, the migration guides); those are fixed by the same rules. A few pages still overflow at phone widths for unrelated reasons (long links, iframes, the home page at 320px); I left them alone.

Corresponding issue: none found (searched open and closed issues and PRs for table/mobile/overflow).

Testing

Built with Zola 0.19.1 (the version in netlify.toml) and zola serve, measuring scrollWidth - innerWidth on /docs/ with Playwright:

  • Before: 320 +85, 360 +45, 375 +30, 400 +5, 740 +79, 760 +69; 0 at 414, 480, 600, 720, 780, 820, 1024, 1440.
  • After: 0 at all of those widths.
  • /reference/ is clean before and after. Light and dark (prefers-color-scheme) checked.
  • Swept 95 pages at 320/375/760/1024: 20 pages overflowed at 320 or 375 before, 9 after, none newly. No page overflows at 1024.
  • renderlint on /docs/ and /reference/ at 375/768/1280: the two viewport-overflow findings (table +30px at 375, Config table +1px at 768) are gone. It now shows one accidental-scrollbar warning for the Config table at 768px (13px of scroll inside the table box, which is the intended behaviour).

The red boxes in the before shots mark the broken part.

Width Before After
375px, light Before, 375px light After, 375px light
375px, dark Before, 375px dark After, 375px dark
760px, light Before, 760px light After, 760px light
760px, dark Before, 760px dark After, 760px dark

Only www/ CSS changed, so npm test (which covers src/, test/ and scripts/) is not affected; this PR targets master as CONTRIBUTING allows for www/-only changes.

I'm the author of renderlint, an open-source CLI I maintain that renders pages in a headless browser and reports layout defects. I ran it on the docs before and after: it flags the overflowing table as viewport-overflow before this change and no longer does after. If it would be useful, I'm happy to open a follow-up PR that runs it on the docs in CI; no pressure either way.

…hones

Tables in the docs made the page scroll sideways at 320-400px, and the Config table did the same around 740-770px. Make .info-table scrollable at every width, make plain tables scrollable at phone widths, and let long inline code wrap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant