Add a max-width attribute for amp-img elements with layout=responsive.
See original GitHub issueSmall AMP images that have layout=responsive
are upscaled if the available space is larger. This can be fixed by adding a special ID and a max-width
style in style amp-custom
, but this is cumbersome if there are lots of images, and if the page styles are generated independently of the page content. You
You could also use the sizes
attribute to achieve this, but that is difficult if there is no simple relationship between the viewport width and the available width for the image (e.g. multiple columns).
It would be great to have an additional max-width
attribute that acts the same as an inline style (style="max-width: 92px"
):
<amp-img src="..." alt="..." width="92" height="64" max-width="92" layout="responsive"></amp-img>
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Layout & media queries - amp.dev
The layout attribute makes working with and creating fully responsive design ... This amp-img element automatically fits the width of its container element...
Read more >How to properly set width and height attributes of amp-img
In this example, the layout="responsive" would be inferred by the AMP engine because image size and formats are specified. When height and width ......
Read more >Using Media Queries in AMP Pages | HTML Goodies
AMP pages shift the control of page responsiveness away from CSS media queries to individual elements. They do so by adding the layout(=" ......
Read more >max-width - CSS: Cascading Style Sheets - MDN Web Docs
The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger...
Read more >Amp-img ALT problems with “” - page 2 - WordPress.org
We have put “” in the attribute layout=responsive. If we don't add those “” ... The 2 elements “fadein” and “:” shall not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looking back on this, I think that @aghassemi is right,
min
andmax
attributes aren’t really that confusing, but we need to be clear in the documentation to what layouts they apply.From what I can tell a table like this one would help:
* maybe, the fill layout could also accept all min/max attributes. ** also, the flex-item layout could use individual, inline min/max limits, but I’m not so sure about these.
@SchnWalter I don’t see how a new attribute (which will be opt-in) would break existing websites. Am I missing something?
Is there a difference between
<amp-img width=400 height=200 layout=shrink-only>
and<amp-img width=400 height=200 max-width=400 max-height=200 layout=responsive>
in terms of the behaviour you had in mind forlayout=shrink-only
?