question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a max-width attribute for amp-img elements with layout=responsive.

See original GitHub issue

Small 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
SchnWaltercommented, Jun 27, 2017

Looking back on this, I think that @aghassemi is right, min and max 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:

layout min-height/max-height min-width/max-width
container
fill ❌ * ❌ *
fixed
fixed-height
flex-item ❌ ** ❌ **
nodisplay
responsive

* 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.

1reaction
aghassemicommented, Mar 20, 2017

@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 for layout=shrink-only?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found