ampproject / ampproject/amphtml

amp-img with layout responsive doesn't work in flexbox

Open
#21,790 4 comments 7 reactions 0 assignees View on GitHub
Component: amp-img P3: When Possible Type: Bug Type: DevX WG: components
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Repros in Chrome here: https://codepen.io/cathyxz/pen/wZgQqY?editors=1100

Basically today @kristoferbaxter discovered that when you have:
```
#container {
display: flex;
height: 100vh;
width: 100vw;
align-items: center;
justify-content: center;
}
```
and
```





```

in AMP, the `` does not display. =(

It turns out that the dimensions of both the `` and the `sizer` are 0x0, and therefore the `` tag is not rendered because the `layoutCallback` is not called.

This does work with `layout="intrinsic"` though, and `layout="responsive"` will work correctly as intended if we set the `flex-basis` property on the ``. But not out of the box. Since this is a commonly used pattern for centering images, it seems like we should document this behaviour and workarounds at least.

Contributor guide

Open the contributing guide

Research direction

Start with the linked CodePen reproduction and the amp-img layout behavior described in the issue, including layoutCallback, responsive versus intrinsic layouts, and flex-basis. Done means documenting the flexbox limitation and the intrinsic and flex-basis workarounds for responsive amp-img images.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, html, javascript
Domain
frontend
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.