How to resize an image to fit in the browser window?

后端 未结 14 1186
再見小時候
再見小時候 2020-11-28 19:00

This seems trivial but after all the research and coding I can\'t get it to work. Conditions are:

  1. The browser window size is unknown. So please don\'t propose
14条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 19:42

    Here is a simple CSS only solution (JSFiddle), works everywhere, mobile and IE included:

    CSS 2.0:

    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
    }
    
    img {
        padding: 0;
        display: block;
        margin: 0 auto;
        max-height: 100%;
        max-width: 100%;
    }
    

    HTML:

    
      
    
    

提交回复
热议问题