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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With