Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make an image to fit its parent dimensions

Tags:

html

css

image

I have some photos which have big sizes, I would like to set them to the Parent's dimension size. If one time the parent dimension is 1200x800, I would like to set the photo dimensions to 1200x800, but also I would like to see the whole image. If my parent dimension is 500x300, I would like the image to be 500x300 and so on.

Is this even possible? I want to shrink the image or expand it according to it's parent's dimension.

Thanks!

like image 795
kfirba Avatar asked Mar 08 '13 14:03

kfirba


People also ask

How do you make a picture full height of a parent?

The image is set as a BLOCK element, min-width/height both set to 100% means to resize the image no matter of its size to be the minimum of 100% of it's parent. min is the key. If by min-height, the image height exceeded the parent's height, no problem.

How do I make an image fit the width of a container?

If your image is portrait, and your container is landscape, you must set height="100%" on the image. If your image is landscape, and your container is portrait, you must set width="100%" on the image.

How do I make an image fit a section?

Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.


1 Answers

The css property that you want is max-width :

Css

img {     max-width:100%; } 

You could add a container around your image and set overflow:hidden to prevent images to get bigger than the defined width/height.

like image 134
soyuka Avatar answered Sep 24 '22 00:09

soyuka