-1

Ok, I guess you've heard this one before... I tried to find a solution, but can't find one. I have a container that covers the left 50% of a screen. Inside the container I want an image to cover the space, and not to strech. Css at this moment is:

height: auto;
max-width: 100%;

Please help!!!

Delal
  • 121
  • 1
  • 2
  • 10
  • 4
    set the image as a background image on the container and set it's `background-size: cover;` – Aaron May 11 '16 at 13:55

3 Answers3

1

• If you have an image larger than the space you want it to cover and you use an img tag to do that, add this to your css:

img {width: auto; height: auto;}

• If, instead, you use a div to place the image as a background-image, use this:

div {
    background-image: url("yourimage.png");
    background-repeat: no-repeat;
    background-size: contain;
}
Angel Politis
  • 9,949
  • 12
  • 43
  • 62
1

You can use it as a background and use the following properties:

background-repeat: no-repeat;
background-position: center center;
background-size: cover;

https://jsfiddle.net/alexndreazevedo/upn7jwfs/

alexndreazevedo
  • 405
  • 1
  • 3
  • 14
0

add img inside your div and set width and height for image in 100%;

<div> <img src=""/> </div>

css

img {
width: 100%;
height: 100%;
}
odpro
  • 96
  • 1
  • 6