Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make images responsive in AMP HTML or I need to declare the image size for each screen resolution in my media queries?

Tags:

amp-html

Most images on my website occupy the whole screen width, so in my current website version (not AMP) I set all the images in my CSS to fill the whole screen width by doing this:

body img { 
  width:100%
}

Is there anything equivalent to this in AMP?

like image 570
Bruno Barbosa Avatar asked Nov 23 '15 18:11

Bruno Barbosa


People also ask

How can an image be made responsive in HTML?

To make an image responsive, you need to give a new value to its width property. Then the height of the image will adjust itself automatically. The important thing to know is that you should always use relative units for the width property like percentage, rather than absolute ones like pixels.

How do I make an image fit my screen size in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels. For example, the original image is 640×960.

Which class will you use to create a responsive image that changes its width based on the browser width?

Create responsive images by adding an . img-responsive class to the <img> tag. The image will then scale nicely to the parent element.


1 Answers

If you specify layout="responsive" as an attribute of the <amp-img> tag then the image will behave roughly like you've described. See an example at http://www.mirror.co.uk/news/uk-news/bonfire-night-2015-how-keep-6767214.amp

The <amp-img> tag requires a height & width. The height and width are used to make sure the space is held open for the image (because AMP images are lazy loaded) and the aspect ratio is respected when it is resized.

like image 156
MatCarey Avatar answered Oct 15 '22 01:10

MatCarey