Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand image inside DIV

Tags:

html

How can I expand an image to have the same height as the div after resizing? Or how can I fill the white space left by the image with a color?

like image 768
Cornel Avatar asked Apr 28 '09 12:04

Cornel


1 Answers

I think this will get you your desired result:

<style>
    div {
    width:50px;
    height:100px;
    }

    div img {
    height:100%;
    }
</style>
<div>
    <img src='path/to/img.gif' />
</div>

The image will now fill to the container div's height and scale its width with its aspect ratio. This could cause the image to expand past the container div's intended width boundaries though so be careful.

like image 112
Dave L Avatar answered Sep 24 '22 05:09

Dave L