HTML img scaling

后端 未结 8 993
闹比i
闹比i 2020-12-12 21:16

I\'m trying to display some large images with HTML img tags. At the moment they go off the edge of the screen; how can I scale them to stay within the browser window?

<
8条回答
  •  醉酒成梦
    2020-12-12 22:07

    No Javascript required.

    IE6 Internet Explorer 6

    Percent only works for the width of an element, but height:100%; does not work without the correct code.

    CSS

    html, body { height:100%; } 
    

    Then using a percentage works properly, and dynamically updates on window resize.

    
    

    You do not need a width attribute, the width scales proportionately as the browser window size is changed.

    And this little gem, is in case the image is scaled up, it will not look (overly) blocky (it interpolates).

    img { -ms-interpolation-mode: bicubic; }
    

    Props go to this source: Ultimate IE6 Cheatsheet: How To Fix 25+ Internet Explorer 6 Bugs

提交回复
热议问题