Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize image proportionally with CSS? [duplicate]

Is there a way to resize (scale down) images proportionally using ONLY CSS?

I'm doing the JavaScript way, but just trying to see if this is possible with CSS.

like image 403
codingbear Avatar asked Apr 24 '09 23:04

codingbear


People also ask

How do I make an image scale proportionally CSS?

A common use is to set max-width: 100%; height: auto; so large images don't exceed their containers width. Another way is the use of object-fit property, this will fit image, without changing the proportionally.

How do I resize an image using CSS without losing the aspect ratio?

The Simple Solution Using CSSBy setting the width property to 100%, you are telling the image to take up all the horizontal space that is available. With the height property set to auto, your image's height changes proportionally with the width to ensure the aspect ratio is maintained.

How do you resize proportionally in CSS?

For proportional resizing purposes, it makes matters extremely simple: Define the width of an element as a percentage (eg: 100%) of the parent's width, then define the element's padding-top (or -bottom) as a percentage so that the height is the aspect ratio you need. And that's it!

How do you scale an image in CSS?

Use the auto Value for Width and the max-height Property to Resize the Image in CSS. We can use the auto value to the width and set the max-height property to specify the width of an image to fit in a container. We will shrink the height of the image to the height of the container.


1 Answers

To resize the image proportionally using CSS:

img.resize {     width:540px; /* you can use % */     height: auto; } 
like image 166
Mkk Avatar answered Oct 11 '22 23:10

Mkk