Skip to content

Fix weird layout bug with images in links#3142

Open
GuillaumeGomez wants to merge 1 commit into
rust-lang:masterfrom
GuillaumeGomez:fix-img-layout-bug
Open

Fix weird layout bug with images in links#3142
GuillaumeGomez wants to merge 1 commit into
rust-lang:masterfrom
GuillaumeGomez:fix-img-layout-bug

Conversation

@GuillaumeGomez

Copy link
Copy Markdown
Member

While working on #3127, I uncovered this bug when pressing tab around:

Screenshot From 2026-06-22 18-36-19

What you see is the link being focused (an image cannot be focused unless we add tabindex to it, which we don't want) when you have an image inside a link (an <img> inside a <a>). To fix, we simply need to make <img> display: block. Once done, we have the expected result:

Screenshot From 2026-06-22 18-36-34

(still not the <img> focused, it's the <a>, but with the correct layout)

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Jun 22, 2026
.content a { text-decoration: none; }
.content a:hover { text-decoration: underline; }
.content img, .content video { max-width: 100%; }
.content img { display: block; }

@ehuss ehuss Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't quite seem like the correct fix to me because it will cause all images to be block displayed instead of inline. This might change the rendering when it is intended for the image to be inline. As a basic example, look at the badges in this repo's README file, and how they are rendered side-by-side. This would force them to be stacked.

How about instead we change the a to have inline-block display instead, like:

Suggested change
.content img { display: block; }
/* When an image is inside an anchor, ensure the focus ring covers the entire
image instead of the anchor's line box. */
.content a:has(img) { display: inline-block; }

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, didn't think about that. I'll add a GUI test as well.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Added the GUI test to ensure the links containing images have the expected size and also that they work correctly side by side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants