Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling img with window, max-width

Tags:

css

I have a 64px that I would want to scale with browser window I have added max-width 100% but the image stays the same.

Html

<img src="../images/GitHub-Mark-64px.png">

CSS

img{
    max-width: 100%;
    height: auto;
}
like image 971
Higeath Avatar asked Oct 31 '25 04:10

Higeath


2 Answers

If your image is smaller than the containing DIV, your CSS rule won't make it any bigger. Try to use width instead of max-width:

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

Addition/Edit after Comments of OP:

You can use any percentage value in this rule, like 60% (or whatever you like), but using width, not max-width (which is only a maximum limit, but not an actual size definition).

But note: It won't really look good if the original image is smaller than displayed and is "blown up".

like image 131
Johannes Avatar answered Nov 02 '25 18:11

Johannes


Try using width instead of max-width in your CSS, width attribute actually sets the width of the img. However, setting it to 100% would actually cover the entire space, so perhaps you should use a lesser percentage accordingly.

like image 36
Divyanshu Maithani Avatar answered Nov 02 '25 17:11

Divyanshu Maithani



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!