Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an image resize to the screens height with CSS?

Unlike many people who want an image to fill out the whole screen, I only care about the image height. How can I use CSS (preferably not JavasScript) to make an image with any size, fill up to 100% of the maximum possible browser window height while keeping aspect ratio of the image, the re-sized width of the image in respect to the browser does not matter.

I'm working with this html:

<div class="images">
  <img/>
</div>

Thank you so much!

like image 610
Mohammad Avatar asked Sep 09 '11 21:09

Mohammad


1 Answers

This might be overkill:

.img {
    position: absolute;
    height: 100%;
    top: 0;
    bottom: 0;
}
like image 193
Joe Avatar answered Oct 01 '22 15:10

Joe