Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit image by height AND width

Tags:

html

css

image

I am having issues limiting my images by either width or height, whichever passes the limit.

Some images I upload are taller than 450px for example, while others are wider than 450px. How can I set them so both width and height won't go over 450px.

This is such a basic thing but I don't know how to do it, I appreciate any help!

EDIT: I was hoping this could be solved with css html, that's why I didn't mention language, but if it's a more complex solution, then I am using meteor.. so javascript and jquery.

like image 205
socialight Avatar asked Jun 11 '26 04:06

socialight


1 Answers

Use the max-width and max-height css properties (and do not set width/height attributes on the img tag)

img{
    max-width:450px;
    max-height:450px;
}

keep in mind that this applies when displaying the images. If you want to limit the real width/height of the image to conserve space on the server you will have to look to uploading plugins with options for scaling down an image.

like image 150
Gabriele Petrioli Avatar answered Jun 13 '26 18:06

Gabriele Petrioli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!