Keep aspect ratio image CSS?

Here is a good code for having your images to keep their aspect ratio, very useful for optimizing your website for mobile devices.

1
2
3
4
5
6
7
#single-content img{
  display: block;
  max-width:100%;
  max-height:100%;
  width: auto;
  height: auto;
}

All the images inside the “single-content” div id will keep their aspect ratio.

ADD A COMMENT: