Skip to content

docs: scale content images to the column width on narrow screens - #3298

Open
ngocanhnckh wants to merge 1 commit into
microsoft:mainfrom
ngocanhnckh:fix/docs-content-images
Open

ngocanhnckh wants to merge 1 commit into
microsoft:mainfrom
ngocanhnckh:fix/docs-content-images

Conversation

@ngocanhnckh

Copy link
Copy Markdown

What is broken

On the docs site home page (https://microsoft.github.io/TypeAgent/) the two 660px figures (TypeAgent-Body1-*.gif, TypeAgent-Body2-*.gif) have no max-width. The stylesheet has no img rule, so they keep their natural width and stick out of the content column. The page is 680px wide at every viewport from 320 to 767px (about 305px of the first figure is off-screen at 375px), so phones scroll sideways. It also happens between 768 and about 990px, where the sidebar leaves less than 660px for the content: at 820px the page is 970px wide.

Cause

docs/assets/css/style.css has no rule limiting images to their container.

Fix

.docs-content img {
  max-width: 100%;
  height: auto;
}

Scoped to the docs content column, so the header and footer are untouched. height: auto keeps the aspect ratio. Widths of 1024px and above are unchanged because the column is already 660px or wider there.

Testing

Built and served with cd docs && npm install && npx eleventy --serve, then measured document.documentElement.scrollWidth with Playwright.

Viewport Page width before Page width after
320 680 320
375 680 375
414 680 414
600 680 600
768 768 768
820 970 820
1024 / 1280 / 1440 equal to viewport equal to viewport, images unchanged (660 x 371 and 660 x 825)

The red marks in the before shots point at the broken part.

Width Before After
375px, light Before, 375px light After, 375px light
414px, light Before, 414px light After, 414px light

The site has no dark theme.

I found this with renderlint, an open-source CLI I maintain that renders pages in a headless browser and reports layout defects. It flags the two images as viewport-overflow (360px beyond a 320px viewport) before the change and reports no layout findings after it. 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.

The two 660px figures on the home page had no max-width, so the page
scrolled sideways on phones and on windows narrower than about 1000px.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
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