Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale image with css to both width and height to scale

Tags:

css

image

The bounding box is approx 1000x600, and some images are 500x100, while some others are 400x100 (extreme examples). Now I'd like to scale both up to the maximum size the bounding box is capable to handle, but keep them to scale.

img {
  width: 100%;
  height: 100%;
}

Won't keep the image to scale.

like image 758
Reactormonk Avatar asked Apr 14 '12 22:04

Reactormonk


People also ask

How do you scale an image in CSS proportionally?

Resize images with the CSS width and height properties Another way of resizing images is using the CSS width and height properties. Set the width property to a percentage value and the height to "auto". The image is going to be responsive (it will scale up and down).

How do you scale a photo proportionally?

If the Shift key is held down whilst moving the handle, then the proportions of the object will be preserved. For example, if I hold Shift and drag the bottom edge upwards to reduce the size by half, then the right edge will automatically move to the left to reduce the width of the object by the same amount.


1 Answers

I don't know if there is a way to do this with just CSS. If you want to achieve something like this then you can use supersized

Alternatively, if you don't care about older browsers, you can look into the CSS3 background-size property. Specifically, I think that setting background-size: cover will do the trick.

Edit - I misunderstood. What you might actually want is background-size: contain, but the downside is that you probably will have to change your html markup, not just your css.

like image 192
logan Avatar answered Sep 27 '22 02:09

logan